from machine import Pin, I2C, ADC
from time import sleep
import dht
from pico_i2c_lcd import I2cLcd
sensor = dht.DHT22(Pin(15))
pot = ADC(Pin(26))
i2c = I2C(1, sda=Pin(2), scl=Pin(3))
lcd = I2cLcd(i2c, 0x27, 2, 16)
led_rojo = Pin(12, Pin.OUT)
led_verde = Pin(11, Pin.OUT)
buzzer = Pin(10, Pin.OUT)
while True:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
presion = int((pot.read_u16() / 65535) * 200) # escala 0–200 mmHg
lcd.clear()
lcd.putstr(f"T:{temp:.1f}C H:{hum:.0f}%")
lcd.move_to(0, 1)
lcd.putstr(f"P:{presion}mmHg")
# Condiciones de alarma
if presion > 140 or temp > 37.5:
led_rojo.on()
led_verde.off()
buzzer.on()
else:
led_rojo.off()
led_verde.on()
buzzer.off()
sleep(3)