from machine import Pin, SoftI2C
import dht
import time
from lcd_api import LcdApi
from machine_i2c_lcd import I2cLcd
led_red = Pin(5, Pin.OUT)
led_green = Pin(4, Pin.OUT)
sensor = dht.DHT22(Pin(14))
I2C_ADDR = 0x27
totalRows = 2
totalColums = 16
i2c = SoftI2C(scl = Pin(22), sda = Pin(21), freq = 10000)
lcd = I2cLcd(i2c, I2C_ADDR, totalRows, totalColums)
lcd.putstr("Hello")
while True:
sensor.measure()
t = sensor.temperature()
h = sensor.humidity()
lcd.clear()
lcd.putstr("Temperature:" + str(t))
lcd.putstr("Humidity:" + str(h))
if t > 40:
led_red.on()
else:
led_red.off()
if h > 50:
led_green.on()
else:
led_green.off()
time.sleep(1)
lcd.clear()