from m5stack import *
from m5ui import *
from uiflow import *
import machine
import time
import unit
setScreenColor(0x222222)
env22 = unit.get(unit.ENV2, unit.PAHUB0)
servo5 = unit.get(unit.SERVO, unit.PORTB)
pir6 = unit.get(unit.PIR, unit.PORTB)
pahub2 = unit.get(unit.PAHUB, unit.PORTA)
tof2 = unit.get(unit.TOF, unit.PAHUB5)
Total = None
PWM0 = machine.PWM(26, freq=50, duty=3, timer=0)
label0 = M5TextBox(46, 49, "Temp :", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(142, 49, "0", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(113, 112, "Please Hold", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(135, 165, "0", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(55, 162, "Total :", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Total = 0
while True:
label1.setText(str(env22.temperature))
while Total < 5:
rgb.setColorFrom(1 , 5 ,0x33cc00)
if (tof2.distance) < 1000:
if (pir6.state) == 1:
label2.setText('Please Hold')
wait(2)
PWM0.duty(12)
wait(2)
PWM0.duty(3)
Total = Total + 1
label3.setText(str(Total))
wait(0.5)
else:
label2.setText('Not Detected')
rgb.setColorFrom(1 , 5 ,0x000000)
rgb.setColorFrom(6 , 10 ,0xff0000)
if btnB.isPressed():
wait(1)
Total = 0
rgb.setColorFrom(6 , 10 ,0x000000)
rgb.setColorFrom(1 , 5 ,0x33cc00)
wait_ms(2)
Comments