from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit
setScreenColor(0x222222)
pir_0 = unit.get(unit.PIR, unit.PORTB)
rfid_0 = unit.get(unit.RFID, unit.PAHUB2)
tof_1 = unit.get(unit.TOF, unit.PAHUB0)
pahub_2 = unit.get(unit.PAHUB, unit.PORTA)
rgb_2 = unit.get(unit.RGB, unit.PORTB)
servo_1 = unit.get(unit.SERVO, unit.PORTC)
shopstatus = None
distancefromjewel = None
label0 = M5TextBox(92, 120, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(92, 96, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(16, 6, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label6 = M5TextBox(71, 197, "A", lcd.FONT_Default, 0xFFFFFF, rotate=0)
shop = M5TextBox(90, 60, "Shop status", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label3 = M5TextBox(92, 141, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label7 = M5TextBox(154, 197, "B", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(249, 197, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label8 = M5TextBox(250, -103, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(16, 30, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label9 = M5TextBox(136, 224, "(Open)", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label10 = M5TextBox(51, 224, "(Close)", lcd.FONT_Default, 0xFFFFFF, rotate=0)
while True:
label2.hide()
label3.hide()
label5.hide()
label0.hide()
label9.hide()
label10.hide()
label4.setText(str(tof_1.distance))
speaker.setVolume(1)
if rfid_0.isCardOn():
speaker.tone(1800, 200)
rgb.setColorAll(0x33ff33)
wait_ms(1)
if (rfid_0.readUid()) == '803f4fc3':
label0.show()
label0.setText('Access authorized')
label3.show()
label3.setText('Please wait')
wait(1)
rgb.setColorAll(0x000000)
label9.show()
label10.show()
label3.setText('Open or Close Store')
while not ((btnA.isPressed()) or (btnB.isPressed())):
wait_ms(1)
label0.hide()
if btnA.isPressed():
shop.setText('Shop Closed')
shopstatus = 0
elif btnB.isPressed():
shop.setText('Shop Open')
shopstatus = 1
label3.hide()
label10.hide()
label9.hide()
wait(2)
if shopstatus == 0:
while not ((btnA.isPressed()) and (rfid_0.readUid()) == '803f4fc3'):
distancefromjewel = int((tof_1.distance))
if distancefromjewel < 120 and (pir_0.state) == 1:
servo_1.write_angle(90)
wait(1)
servo_1.write_angle(0)
while not (rfid_0.readUid()) == '803f4fc3':
label5.show()
speaker.setVolume(10)
distancefromjewel = int((tof_1.distance))
rgb_2.setColor(1, 0xff0000)
rgb_2.setColor(2, 0xff0000)
rgb_2.setColor(3, 0xff0000)
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
label5.setText('Scan ID card to turn off')
wait_ms(500)
rgb.setColorAll(0x33ff33)
speaker.tone(1000, 5000)
label2.show()
label5.show()
label5.setText('Press A to disable shop security')
label2.setText('Ignore to keep current settings')
wait(2)
rgb.setColorAll(0x000000)
elif (pir_0.state) == 1:
rgb_2.setColor(1, 0xffffcc)
rgb_2.setColor(2, 0xffffcc)
rgb_2.setColor(3, 0xffffcc)
elif (pir_0.state) == 0:
rgb_2.setColor(3, 0x000000)
rgb_2.setColor(2, 0x000000)
rgb_2.setColor(1, 0x000000)
label2.hide()
label5.hide()
speaker.tone(1000, 5000)
label5.show()
label5.setText('Shop security disabled')
rgb.setColorAll(0xff0000)
wait(2)
label5.hide()
elif shopstatus == 1:
while not ((btnB.isPressed()) and (rfid_0.readUid()) == '803f4fc3'):
distancefromjewel = int((tof_1.distance))
if distancefromjewel < 120 and (pir_0.state) == 1:
servo_1.write_angle(90)
wait(1)
servo_1.write_angle(0)
while not (rfid_0.readUid()) == '803f4fc3':
label5.show()
speaker.setVolume(10)
distancefromjewel = int((tof_1.distance))
rgb_2.setColor(1, 0xff0000)
rgb_2.setColor(2, 0xff0000)
rgb_2.setColor(3, 0xff0000)
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
label5.setText('Scan ID card to turn off')
wait_ms(500)
rgb.setColorAll(0x33ff33)
speaker.tone(1000, 5000)
label2.show()
label5.show()
label5.setText('Press B to disable shop security')
label2.setText('Ignore to keep current settings')
wait(2)
rgb.setColorAll(0x000000)
rgb_2.setColor(1, 0x000000)
rgb_2.setColor(2, 0x000000)
rgb_2.setColor(3, 0x000000)
elif (pir_0.state) == 1:
rgb_2.setColor(1, 0xffffcc)
rgb_2.setColor(2, 0xffffcc)
rgb_2.setColor(3, 0xffffcc)
elif (rfid_0.readUid()) == '803f4fc3':
label5.show()
label2.show()
label5.setText('Security system disabled,')
label2.setText(' scan card again to enable')
rgb.setColorAll(0x33ff33)
speaker.tone(1000, 5000)
wait(3)
while not (rfid_0.readUid()) == '803f4fc3':
wait_ms(1)
speaker.tone(1000, 5000)
rgb.setColorAll(0xff0000)
wait(2)
rgb.setColorAll(0x000000)
label3.hide()
label2.hide()
label5.hide()
label5.show()
label5.setText('Shop security disabled')
speaker.tone(1000, 5000)
rgb.setColorAll(0xff0000)
wait(2)
label5.hide()
elif (rfid_0.readUid()) != '803f4fc3':
label0.show()
rgb.setColorAll(0xff0000)
label0.setText('Access denied')
wait(2)
rgb.setColorAll(0x000000)
label0.hide()
else:
rgb_2.setColor(1, 0x000000)
rgb_2.setColor(2, 0x000000)
rgb_2.setColor(3, 0x000000)
shop.setText('Shop Status')
label0.setText('Please scan your card')
label1.setText('RFID Card ID')
rgb.setColorAll(0x000000)
wait_ms(2)
Comments