from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit
setScreenColor(0x25706c)
earth_0 = unit.get(unit.EARTH, unit.PORTB)
env2_0 = unit.get(unit.ENV2, unit.PORTA)
servo_1 = unit.get(unit.SERVO, unit.PORTC)
a = None
b = None
c = None
Humidity = M5TextBox(200, 17, "Humidity:", lcd.FONT_DejaVu18, 0xffc4c4, rotate=0)
Temperature = M5TextBox(14, 17, "Temperature:", lcd.FONT_DejaVu18, 0xff0000, rotate=0)
HumidityShow = M5TextBox(234, 42, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
TemperatureShow = M5TextBox(60, 42, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Moisture = M5TextBox(112, 164, "Moisture:", lcd.FONT_DejaVu18, 0x00c0ff, rotate=0)
MoistureShow = M5TextBox(145, 189, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
rectangleHumid = M5Rect(223, 72, 50, 10, 0xFFFFFF, 0xFFFFFF)
rectangle0 = M5Rect(177, 117, 150, 5, 0xFFFFFF, 0xFFFFFF)
rectangleTemp = M5Rect(48, 72, 50, 10, 0xFFFFFF, 0xFFFFFF)
rectangle1 = M5Rect(0, 117, 150, 5, 0xFFFFFF, 0xFFFFFF)
rectangleMoist = M5Rect(134, 207, 50, 10, 0xFFFFFF, 0xFFFFFF)
circle = M5Circle(160, 120, 30, 0xFFFFFF, 0xFFFFFF)
image0 = M5Img(147, 107, "res/thumbsup.jpg", True)
import math
while True:
HumidityShow.setText(str((str(round(env2_0.humidity)) + str('%'))))
TemperatureShow.setText(str((str(round(env2_0.temperature)) + str('C'))))
MoistureShow.setText(str(round(earth_0.analogValue)))
if (env2_0.humidity) >= 50 and (env2_0.humidity) <= 80:
rectangleHumid.setBgColor(0x33ff33)
a = 1
else:
rectangleHumid.setBgColor(0xff0000)
a = 0
if (env2_0.temperature) >= 21 and (env2_0.temperature) <= 28:
rectangleTemp.setBgColor(0x33ff33)
b = 1
else:
rectangleTemp.setBgColor(0xff0000)
b = 0
if (earth_0.analogValue) >= 100 and (earth_0.analogValue) <= 1000:
rectangleMoist.setBgColor(0x33ff33)
c = 1
else:
rectangleMoist.setBgColor(0xff0000)
c = 0
if a == 1 and b == 1 and c == 1:
circle.setBgColor(0x33ff33)
image0.show()
else:
circle.setBgColor(0xff0000)
image0.hide()
if (earth_0.analogValue) <= 100:
servo_1.write_angle(5)
wait(2)
servo_1.write_angle(60)
wait(2)
servo_1.write_angle(5)
wait_ms(2)
Comments