import time
import dht
from machine import Pin, SoftI2C, time_pulse_us
from i2c_lcd import I2cLcd
lcdI2C = SoftI2C(scl=Pin(17), sda=Pin(18), freq=100000)
sensor = dht.DHT22(Pin(12))
led = Pin(21, Pin.OUT)
lcd = I2cLcd(lcdI2C, 39, 2, 16)
while True:
sensor.measure()
t = sensor.temperature()
h = sensor.humidity()
lcd.clear()
lcd.putstr("Temp: " + str(t) + " C\n")
lcd.putstr("Humidity: " + str(h) + "%")
time.sleep(1)
if t > 40:
led.on()
else:
led.off()
time.sleep(1)
lcd.clear()