from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit
setScreenColor(0x000000)
pahub2 = unit.get(unit.PAHUB, unit.PORTA)
rfid4 = unit.get(unit.RFID, unit.PAHUB0)
rfid5 = unit.get(unit.RFID, unit.PAHUB5)
pbhub1 = unit.get(unit.PBHUB, unit.PAHUB2)
servo0 = unit.get(unit.SERVO, unit.PORTB)
tof0 = unit.get(unit.TOF, unit.PAHUB4)
tof1 = unit.get(unit.TOF, unit.PAHUB1)
NUM = None
NUMBER = M5TextBox(76, 92, "NUM", lcd.FONT_DejaVu72, 0x31b538, rotate=0)
Situation = M5TextBox(13, 189, "Situation", lcd.FONT_DejaVu40, 0x286b3d, rotate=0)
RFID = M5TextBox(225, 11, "RFID CODE", lcd.FONT_Default, 0x3e974f, rotate=0)
label3 = M5TextBox(21, 45, "No. of people Allowed", lcd.FONT_DejaVu24, 0xfffbfb, rotate=0)
TOF = M5TextBox(33, 11, "TOF", lcd.FONT_Default, 0x327625, rotate=0)
from numbers import Number
def multiBtnCb_AB():
global NUM
NUM = (NUM if isinstance(NUM, Number) else 0) + -1
NUMBER.setText(str(NUM))
pass
btn.multiBtnCb(btnA,btnB,multiBtnCb_AB)
def multiBtnCb_BC():
global NUM
NUM = (NUM if isinstance(NUM, Number) else 0) + 1
NUMBER.setText(str(NUM))
pass
btn.multiBtnCb(btnB,btnC,multiBtnCb_BC)
def multiBtnCb_AC():
global NUM
NUM = 2
NUMBER.setText(str(NUM))
pass
btn.multiBtnCb(btnA,btnC,multiBtnCb_AC)
NUM = 2
NUMBER.setText(str(NUM))
servo0.write_angle(0)
while True:
rgb.setColorAll(0x000000)
if NUM > 0 and NUM < 2:
if rfid4.isCardOn():
RFID.setText(str(rfid4.readUid()))
if (rfid4.readUid()) == '8843842f6' or (rfid4.readUid()) == 'f05ea9ad':
speaker.tone(3000, 200)
pbhub1.setColor(2, 0, 1, 0x009900)
wait(1)
pbhub1.setColor(2, 0, 1, 0x000000)
servo0.write_angle(90)
for count in range(20):
TOF.setText(str(tof1.distance))
if (tof1.distance) > 100:
pbhub1.setColor(2, 1, 1, 0xffcc33)
wait(0.5)
pbhub1.setColor(2, 1, 1, 0x000000)
wait(0.5)
else:
break
wait(2)
servo0.write_angle(0)
NUM = (NUM if isinstance(NUM, Number) else 0) + -1
NUMBER.setText(str(NUM))
else:
speaker.tone(200, 200)
pbhub1.setColor(2, 2, 1, 0xff0000)
wait(1)
pbhub1.setColor(2, 2, 1, 0x000000)
if rfid5.isCardOn():
RFID.setText(str(rfid5.readUid()))
if (rfid5.readUid()) == '8843842f6' or (rfid5.readUid()) == 'f05ea9ad':
speaker.tone(3000, 200)
pbhub1.setColor(3, 0, 1, 0x009900)
wait(1)
pbhub1.setColor(3, 0, 1, 0x000000)
servo0.write_angle(90)
for count2 in range(20):
TOF.setText(str(tof0.distance))
if (tof0.distance) > 100:
pbhub1.setColor(3, 1, 1, 0xffcc33)
wait(0.5)
pbhub1.setColor(3, 1, 1, 0x000000)
wait(0.5)
else:
break
wait(2)
servo0.write_angle(0)
NUM = (NUM if isinstance(NUM, Number) else 0) + 1
NUMBER.setText(str(NUM))
else:
speaker.tone(200, 200)
pbhub1.setColor(3, 2, 1, 0xff0000)
wait(1)
pbhub1.setColor(3, 2, 1, 0x000000)
else:
if NUM == 0:
if rfid5.isCardOn():
RFID.setText(str(rfid5.readUid()))
if (rfid5.readUid()) == '8843842f6' or (rfid5.readUid()) == 'f05ea9ad':
speaker.tone(3000, 200)
pbhub1.setColor(3, 0, 1, 0x009900)
wait(1)
pbhub1.setColor(3, 0, 1, 0x000000)
servo0.write_angle(90)
for count3 in range(20):
TOF.setText(str(tof0.distance))
if (tof0.distance) > 100:
pbhub1.setColor(3, 1, 1, 0xffcc33)
wait(0.5)
pbhub1.setColor(3, 1, 1, 0x000000)
wait(0.5)
else:
break
wait(2)
servo0.write_angle(0)
NUM = (NUM if isinstance(NUM, Number) else 0) + 1
NUMBER.setText(str(NUM))
else:
speaker.tone(200, 200)
pbhub1.setColor(3, 2, 1, 0xff0000)
wait(1)
pbhub1.setColor(3, 2, 1, 0x000000)
if NUM == 2:
if rfid4.isCardOn():
RFID.setText(str(rfid4.readUid()))
if (rfid4.readUid()) == '8843842f6' or (rfid4.readUid()) == 'f05ea9ad':
speaker.tone(3000, 200)
pbhub1.setColor(2, 0, 1, 0x009900)
wait(1)
pbhub1.setColor(2, 0, 1, 0x000000)
servo0.write_angle(90)
for count4 in range(20):
TOF.setText(str(tof1.distance))
if (tof1.distance) > 100:
pbhub1.setColor(2, 1, 1, 0xffcc33)
wait(0.5)
pbhub1.setColor(2, 1, 1, 0x000000)
wait(0.5)
else:
break
wait(2)
servo0.write_angle(0)
NUM = (NUM if isinstance(NUM, Number) else 0) + -1
NUMBER.setText(str(NUM))
else:
speaker.tone(200, 200)
pbhub1.setColor(2, 2, 1, 0xff0000)
wait(1)
pbhub1.setColor(2, 2, 1, 0x000000)
if NUM < 0 or NUM > 2:
Situation.setText('Required Staff')
speaker.tone(1800, 200)
rgb.setColorAll(0xcc0000)
wait(1)
rgb.setColorAll(0x000000)
NUMBER.setColor(0xcc0000)
Situation.setColor(0xcc0000)
if NUM > 0 and NUM <= 2:
Situation.setText('Please Enter...')
NUMBER.setColor(0x33cc00)
Situation.setColor(0x33cc00)
if NUM == 0:
Situation.setText('Please Wait...')
NUMBER.setColor(0xcc0000)
Situation.setColor(0xcc0000)
wait_ms(2)
Comments