from machine import I2C, Pin
from time import sleep
from pico_i2c_lcd import I2cLcd
from dht import DHT22
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
I2C_ADDR = i2c.scan()[0]
dht = DHT22(Pin(5))
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
led_rojo = Pin(16, Pin.OUT) # LED rojo en GPIO10
led_azul = Pin(17, Pin.OUT) # LED azul en GPIO11
while True:
dht.measure() #para la lectura del sensor
temp = dht.temperature()
hum = dht.humidity()
print("Temperatura: {}°C Humedad: {:.1f}% ".format(temp, hum))
lcd.clear()
lcd.putstr('Temp: ' + str(temp) + " C")
lcd.move_to(0,1)
lcd.putstr('Hum: ' + str(hum) + " %")
if temp > 38:
led_rojo.value(1) # Enciende LED rojo si temperatura > 50°C
else:
led_rojo.value(0) # Apaga LED rojo
if hum > 50:
led_azul.value(1) # Enciende LED azul si humedad > 50%
else:
led_azul.value(0) # Apaga LED azul
sleep(2)