# 左侧的旋钮是模拟水箱水位的
# 右侧的旋钮是用来调整湿度阈值的
# LED 部分是模拟加湿器运作的 亮灯代表加湿器开始工作
# Written by Owen, MIEC RIDS.
from machine import ADC
from machine import Pin
from machine import SoftI2C
from esp32_i2c_1602lcd import I2cLcd
from time import sleep
from dht import DHT22
temp = [0]
temp[0] = 0
status = False
d = ADC(Pin(1))
f = DHT22(Pin(4))
wl = ADC(Pin(19))
DEFAULT_I2C_ADDR = 0x27
i2c = SoftI2C(sda=Pin(2), scl=Pin(42), freq=100000)
lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)
led = Pin(14, Pin.OUT)
output=[0, 0]
while True:
lcd.backlight_on()
f.measure()
hold = int(d.read_u16() / 65535 * 100)
level = int(wl.read_u16() / 65535 * 100)
d_humid = f.humidity()
d_temp = f.temperature()
lcd.putstr("\n\n")
if temp[0] != hold:
lcd.putstr("Set Humid: \n" + str(hold) + "% \n")
elif d_humid < hold and level < 0.15:
lcd.putstr(" CHECK WATER TANK!!\n")
lcd.backlight_off()
else:
output[0] = "Humid: " + str(d_humid) + " %"
output[1] = "Temp: " + str(d_temp) + " C"
lcd.putstr(output[0] + " "*(15-len(output[0])) + "\n")
lcd.putstr(output[1] + " "*(15-len(output[1])) + "\n")
temp[0] = hold
print("阈值:", hold, "%")
print("水位:", level, "%")
print("湿度:", d_humid, "%")
if d_humid < hold:
if level >= 0.15 and status==False:
led.on()
status = True
print("开始加湿")
elif level < 0.15:
status = False
led.off()
print("需要加水")
else:
print("正常工作")
else:
status = False
led.off()
print("停止加湿")
sleep(1)