from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit
setScreenColor(0x222222)
tof2 = unit.get(unit.TOF, unit.PORTA)
pir1 = unit.get(unit.PIR, unit.PORTB)
servo2 = unit.get(unit.SERVO, unit.PORTB)
on = None
off = None
stockchecker = None
label1 = M5TextBox(7, 31, "There is a customer", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label0 = M5TextBox(7, 32, "No customer Detected", lcd.FONT_Default, 0xFFFFFF, rotate=0)
title0 = M5Title(title=" safety & convenience system", x=3, fgcolor=0xFFFFFF, bgcolor=0x5050b2)
label2 = M5TextBox(146, 161, ".", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(146, 190, ".", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label6 = M5TextBox(32, 107, "ALERTING POLICE!!!", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label5 = M5TextBox(54, 107, "No one detected", lcd.FONT_DejaVu24, 0x1af326, rotate=0)
label4 = M5TextBox(26, 99, "INTRUDER!!!", lcd.FONT_DejaVu40, 0xe60f0f, rotate=0)
def buttonA_wasPressed():
global on, off, stockchecker
on = True
off = False
pass
btnA.wasPressed(buttonA_wasPressed)
def buttonB_wasPressed():
global on, off, stockchecker
on = False
off = True
pass
btnB.wasPressed(buttonB_wasPressed)
def buttonC_wasPressed():
global on, off, stockchecker
on = False
off = False
label6.show()
rgb.setColorAll(0xffffff)
pass
btnC.wasPressed(buttonC_wasPressed)
label1.setText('There is a customer')
label0.setText('No customer Detected')
label1.hide()
label4.hide()
label5.hide()
label0.hide()
label6.hide()
while True:
if on == True:
while on == True:
label4.hide()
stockchecker = tof2.distance
label3.setText(str(tof2.distance))
if stockchecker <= 50:
label2.setText('stock is FULL')
rgb.setColorAll(0x33ff33)
elif stockchecker > 50 and stockchecker <= 150:
label2.setText('stock level is MODERATE')
rgb.setColorAll(0x3333ff)
elif stockchecker > 150 and stockchecker <= 250:
label2.setText('Stock level is LOW')
rgb.setColorAll(0xff99ff)
elif stockchecker > 250:
label2.setText('NO stock detected')
rgb.setColorAll(0xff0000)
if (pir1.state) == 1:
label0.hide()
label1.show()
rgb.setColorAll(0x33cc00)
speaker.tone(1800, 1000)
speaker.setVolume(0.2)
servo2.write_angle(90)
wait(3)
servo2.write_angle(0)
wait(3)
else:
label0.show()
label1.hide()
rgb.setColorAll(0x000000)
servo2.write_angle(0)
elif off == True:
while off == True:
label0.hide()
label1.hide()
label2.hide()
label3.hide()
label4.hide()
label5.hide()
servo2.write_angle(0)
if (pir1.state) == 1:
label4.show()
label5.hide()
speaker.tone(1800, 1000)
rgb.setColorAll(0xcc0000)
else:
label4.hide()
label5.show()
rgb.setColorAll(0x000000)
wait_ms(2)
Comments