from machine import I2C, Pin
from utime import sleep
from pico_i2c_lcd import I2cLcd
from dht import DHT22
led_red = Pin(10, Pin.OUT)
led_green = Pin(11, Pin.OUT)
led_blue = Pin(12, Pin.OUT)
# Configuração do barramento I2C nos pinos GP8 (SDA) e GP9 (SCL)
i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=400000)
sensor = DHT22(Pin(18))
# Descobre o endereço I2C automaticamente (geralmente é 0x27 ou 0x3F)
I2C_ADDR = i2c.scan()[0]
# Cria o objeto do display LCD com 2 linhas e 16 colunas
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
# Mensagem inicial
lcd.move_to(0,0)
lcd.putstr("Alarme de")
lcd.move_to(0,1)
lcd.putstr("Temperatura")
sleep(2)
lcd.clear()
while True:
sensor.measure()
temperatura = sensor.temperature()
if temperatura < 20:
led_red.value(0)
led_green.value(0)
led_blue.value(1)
lcd.clear()
lcd.move_to(0,0)
lcd.putstr("Temperatura:")
lcd.move_to(0,1)
lcd.putstr(f"{temperatura}C - Baixa")
sleep(2)
elif temperatura >= 20 and temperatura <= 30:
led_red.value(0)
led_green.value(1)
led_blue.value(0)
lcd.clear()
lcd.move_to(0,0)
lcd.putstr("Temperatura:")
lcd.move_to(0,1)
lcd.putstr(f"{temperatura}C - Media")
sleep(2)
else:
led_red.value(1)
led_green.value(0)
led_blue.value(0)
lcd.clear()
lcd.move_to(0,0)
lcd.putstr("Temperatura:")
lcd.move_to(0,1)
lcd.putstr(f"{temperatura}C - Alta")
sleep(2)