from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit
remoteInit()
setScreenColor(0xffffff)
servo_2 = unit.get(unit.SERVO, unit.PORTB)
pahub_2 = unit.get(unit.PAHUB, unit.PORTA, 0x70)
rfid_2 = unit.get(unit.RFID, unit.PAHUB4)
env2_2 = unit.get(unit.ENV2, unit.PAHUB0)
pbhub_0 = unit.get(unit.PBHUB, unit.PAHUB2)
rgb_0 = unit.get(unit.RGB, unit.PORTE)
earth_2 = unit.get(unit.EARTH, unit.PORTD)
servo_4 = unit.get(unit.SERVO, unit.PORTE)
switch_value = None
slider_value = None
Temperature = M5TextBox(8, 23, "Temperature", lcd.FONT_Comic, 0x000000, rotate=0)
humidity = M5TextBox(8, 53, "Humidity", lcd.FONT_Comic, 0x000000, rotate=0)
Temp = M5TextBox(176, 22, "text", lcd.FONT_Comic, 0x000000, rotate=0)
DegC = M5TextBox(249, 22, "Deg C", lcd.FONT_Comic, 0x000000, rotate=0)
humi = M5TextBox(176, 53, "text", lcd.FONT_Comic, 0x000000, rotate=0)
Percentage = M5TextBox(264, 53, "%", lcd.FONT_Comic, 0x000000, rotate=0)
Question = M5TextBox(15, 83, "Question", lcd.FONT_Comic, 0x000000, rotate=0)
image0 = M5Img(100, 113, "res/water.jpg", True)
image1 = M5Img(100, 113, "res/dehumi.jpg", True)
image2 = M5Img(100, 113, "res/welcome.jpg", True)
# Describe this function...
def Humidity():
global switch_value, slider_value
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x99ffff)
wait(1)
pbhub_0.setServoAngle(2, 0, 180)
rgb.setColorAll(0x000000)
wait(1)
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x99ffff)
wait(1)
pbhub_0.setServoAngle(2, 0, 180)
rgb.setColorAll(0x000000)
wait(1)
speaker.sing(523, 1/2)
speaker.sing(587, 1/2)
speaker.sing(523, 1/2)
speaker.sing(494, 1/2)
speaker.sing(523, 1/2)
speaker.sing(262, 1/2)
speaker.sing(392, 1/2)
speaker.sing(262, 1/2)
speaker.sing(523, 1/2)
speaker.sing(587, 1/2)
speaker.sing(523, 1/2)
speaker.sing(494, 1/2)
speaker.sing(523, 1/2)
speaker.sing(262, 1/2)
speaker.sing(392, 1/2)
speaker.sing(262, 1/2)
speaker.sing(523, 1/2)
speaker.sing(587, 1/2)
speaker.sing(523, 1/2)
speaker.sing(494, 1/2)
speaker.sing(523, 1/2)
speaker.sing(587, 1/2)
speaker.sing(659, 1/2)
speaker.sing(698, 1/2)
speaker.sing(784, 1/2)
speaker.sing(698, 1/2)
speaker.sing(659, 1/2)
speaker.sing(587, 1/2)
speaker.sing(523, 1)
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x99ffff)
wait(1)
pbhub_0.setServoAngle(2, 0, 180)
rgb.setColorAll(0x000000)
wait(1)
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x99ffff)
wait(1)
pbhub_0.setServoAngle(2, 0, 180)
rgb.setColorAll(0x000000)
wait(1)
# Describe this function...
def water():
global switch_value, slider_value
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x33cc00)
wait(1)
pbhub_0.setServoAngle(2, 0, 180)
rgb.setColorAll(0x333333)
wait(1)
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x33cc00)
wait(1)
pbhub_0.setServoAngle(2, 0, 180)
rgb.setColorAll(0x333333)
wait(1)
speaker.sing(523, 1)
speaker.sing(392, 1)
speaker.sing(349, 1)
speaker.sing(330, 1)
speaker.sing(523, 1)
speaker.sing(392, 1)
speaker.sing(349, 1)
speaker.sing(330, 1)
speaker.sing(523, 1)
speaker.sing(392, 1)
speaker.sing(349, 1)
speaker.sing(330, 1)
speaker.sing(349, 1)
speaker.sing(330, 1)
speaker.sing(392, 1)
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x33cc00)
wait(1)
pbhub_0.setServoAngle(2, 0, 180)
rgb.setColorAll(0x333333)
wait(1)
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x33cc00)
wait(1)
pbhub_0.setServoAngle(2, 0, 180)
rgb.setColorAll(0x333333)
wait(1)
# Describe this function...
def Door():
global switch_value, slider_value
speaker.sing(330, 1/2)
speaker.sing(349, 1/2)
speaker.sing(392, 1/2)
speaker.sing(196, 1/2)
speaker.sing(392, 1/2)
speaker.sing(196, 1/2)
speaker.sing(392, 1/2)
speaker.sing(196, 1/2)
speaker.sing(392, 1/2)
speaker.sing(196, 1/2)
speaker.sing(392, 1/2)
speaker.sing(448, 1/2)
speaker.sing(392, 1/2)
speaker.sing(349, 1/2)
speaker.sing(330, 1/2)
speaker.sing(165, 1/2)
speaker.sing(330, 1/2)
speaker.sing(165, 1/2)
speaker.sing(330, 1/2)
speaker.sing(165, 1/2)
speaker.sing(330, 1/2)
speaker.sing(349, 1/2)
speaker.sing(330, 1/2)
speaker.sing(294, 1/2)
speaker.sing(262, 1/2)
speaker.sing(247, 1/2)
speaker.sing(220, 1)
speaker.sing(220, 1/2)
speaker.sing(247, 1/2)
speaker.sing(262, 1/2)
speaker.sing(294, 1/2)
speaker.sing(196, 1)
speaker.sing(262, 1)
speaker.sing(294, 1/2)
speaker.sing(330, 1/2)
speaker.sing(294, 2)
speaker.sing(294, 1)
speaker.sing(262, 1)
def buttonA_wasPressed():
global switch_value, slider_value
setScreenColor(0xffffff)
Question.setText('Door Opening!!')
image2.show()
servo_2.write_angle(90)
rgb.setColorAll(0x6666cc)
wait(3)
servo_2.write_angle(0)
rgb.setColorAll(0x333333)
wait(3)
pass
btnA.wasPressed(buttonA_wasPressed)
def buttonB_wasPressed():
global switch_value, slider_value
Question.hide()
lcd.qrcode('https://flow.m5stack.com/remote?id=1081402462440783872', 72, 32, 176)
wait(7)
pass
btnB.wasPressed(buttonB_wasPressed)
def switch_2_callback(switch_value):
global slider_value, servo_2, pahub_2, rfid_2, env2_2, pbhub_0, rgb_0, earth_2, servo_4, Door, Humidity, water
if switch_value == 0:
pbhub_0.setColorPos(0, 0, 0x000000)
elif switch_value == 1:
pbhub_0.setColorPos(0, 0, 0xffffff)
def slider_2_callback(slider_value):
global switch_value, servo_2, pahub_2, rfid_2, env2_2, pbhub_0, rgb_0, earth_2, servo_4, Door, Humidity, water
if slider_value <= 20:
pbhub_0.setBrightness(0, 20)
elif slider_value > 20 and slider_value <= 50:
pbhub_0.setBrightness(0, 50)
elif slider_value > 50 and slider_value <= 70:
pbhub_0.setBrightness(0, 70)
elif slider_value > 70:
pbhub_0.setBrightness(0, 100)
def button_remotename_callback():
global switch_value, slider_value, servo_2, pahub_2, rfid_2, env2_2, pbhub_0, rgb_0, earth_2, servo_4, Door, Humidity, water
setScreenColor(0xffffff)
Question.setText('Door Opening!!')
image2.show()
servo_2.write_angle(90)
rgb.setColorAll(0x6666cc)
wait(3)
servo_2.write_angle(0)
rgb.setColorAll(0x333333)
wait(1)
def gauge_2_callback():
global switch_value, slider_value, servo_2, pahub_2, rfid_2, env2_2, pbhub_0, rgb_0, earth_2, servo_4, Door, Humidity, water
return earth_2.analogValue
def button_7_callback():
global switch_value, slider_value, servo_2, pahub_2, rfid_2, env2_2, pbhub_0, rgb_0, earth_2, servo_4, Door, Humidity, water
setScreenColor(0xffffff)
Question.setText('Start Watering!!')
image0.show()
humidity.setText('Soil moisture')
humi.setText(str(earth_2.analogValue))
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x33cc00)
wait(3)
rgb.setColorAll(0x333333)
pbhub_0.setServoAngle(2, 0, 180)
def gauge_1_callback():
global switch_value, slider_value, servo_2, pahub_2, rfid_2, env2_2, pbhub_0, rgb_0, earth_2, servo_4, Door, Humidity, water
return env2_2.humidity
def button_2_callback():
global switch_value, slider_value, servo_2, pahub_2, rfid_2, env2_2, pbhub_0, rgb_0, earth_2, servo_4, Door, Humidity, water
setScreenColor(0xffffff)
Question.setText('Start Dehumidifying!')
image1.show()
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x99ffff)
wait(3)
pbhub_0.setServoAngle(2, 0, 180)
rgb.setColorAll(0x000000)
Temperature.hide()
humidity.hide()
Temp.hide()
DegC.hide()
humi.hide()
Percentage.hide()
Question.setText('Tap Your Card to Unlock the Door!!')
image0.hide()
image1.hide()
image2.hide()
while True:
if rfid_2.isCardOn():
if (rfid_2.readUid()) == 'd0ba2c4f9':
setScreenColor(0x33cc00)
humi.setText('Welcome!')
Question.setText('Group 2')
speaker.tone(1800, 500)
wait(2)
servo_2.write_angle(90)
wait(7)
rgb.setColorAll(0x33cc00)
servo_2.write_angle(0)
Door()
pbhub_0.setColorPos(0, 1, 0xffffff)
setScreenColor(0xffffff)
Temperature.setText('You can get the QR by pressing Button B as well')
lcd.qrcode('https://flow.m5stack.com/remote?id=1081402462440783872', 90, 80, 150)
wait(7)
setScreenColor(0xffffff)
Temperature.setText('Temperature')
humidity.show()
Temp.setText(str(env2_2.temperature))
humi.setText(str(env2_2.humidity))
DegC.show()
Percentage.show()
Question.hide()
wait(5)
if (env2_2.humidity) >= 45:
Temp.setText(str(env2_2.temperature))
humi.setText(str(env2_2.humidity))
Question.setText('Start Dehumidifying!')
image1.show()
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x99ffff)
wait(1)
Humidity()
pbhub_0.setServoAngle(2, 0, 180)
rgb.setColorAll(0x000000)
wait(1)
wait(7)
humidity.setText('Soil moisture')
humi.setText(str(earth_2.analogValue))
if (earth_2.analogValue) <= 600:
Temperature.hide()
Temp.hide()
DegC.hide()
Percentage.hide()
Temperature.hide()
rgb.setColorAll(0xff0000)
wait(2)
Question.setText('Start Watering!!')
image0.show()
humidity.setText('Soil moisture')
humi.setText(str(earth_2.analogValue))
pbhub_0.setServoAngle(2, 0, 0)
rgb.setColorAll(0x33cc00)
wait(1)
water()
pbhub_0.setServoAngle(2, 0, 180)
rgb.setColorAll(0x333333)
wait(1)
image0.hide()
image1.hide()
wait(3)
humidity.hide()
humi.hide()
while True:
Question.setText('Press Button A to open the door!!')
image2.hide()
wait_ms(2)
elif (rfid_2.readUid()) != 'd0ba2c4f9':
setScreenColor(0xff0000)
Temperature.setText('Intruder!!')
speaker.tone(100, 200)
wait_ms(2)
Comments
Please log in or sign up to comment.