from machine import I2C, Pin
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_azul = Pin(17, Pin.OUT)
led_alerta = Pin(18, Pin.OUT)
while True:
dht.measure()
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)
if temp > 38 and hum > 50:
lcd.putstr("ALERTA")
led_rojo.value(0)
led_azul.value(0)
for _ in range(3): # Parpadea 3 veces
led_alerta.value(1)
sleep(0.2)
led_alerta.value(0)
sleep(0.2)
else:
# No hay alerta, gestionar temperatura y humedad individualmente
if temp > 38:
lcd.putstr("Temp. alta")
led_rojo.value(1) # Enciende LED rojo si la temp es alta
else:
led_rojo.value(0) # Apaga LED rojo si la temp baja
if hum > 50:
lcd.putstr("Humedad alta")
led_azul.value(1) # Enciende LED azul si la humedad es alta
else:
led_azul.value(0) # Apaga LED azul si la humedad baja
#led_alerta.value(0) # Apaga LED de alerta si no hay alerta
sleep(5)