from machine import Pin, I2C
from time import sleep
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
# Configurar LCD I2C
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
lcd = I2cLcd(i2c, 0x27, 2, 16)
# Configurar LEDs
led_rojo = Pin(2, Pin.OUT)
led_amarillo = Pin(3, Pin.OUT)
led_verde = Pin(4, Pin.OUT)
# Configurar Botones (con PULL_UP)
btn_rojo = Pin(5, Pin.IN, Pin.PULL_UP)
btn_amarillo = Pin(6, Pin.IN, Pin.PULL_UP)
btn_verde = Pin(7, Pin.IN, Pin.PULL_UP)
lcd.putstr("Sistema listo!")
while True:
if not btn_rojo.value():
led_rojo.value(1)
lcd.clear()
lcd.putstr("LED ROJO encendido")
sleep(0.5)
else:
led_rojo.value(0)
if not btn_amarillo.value():
led_amarillo.value(1)
lcd.clear()
lcd.putstr("LED AMARILLO on")
sleep(0.5)
else:
led_amarillo.value(0)
if not btn_verde.value():
led_verde.value(1)
lcd.clear()
lcd.putstr("LED VERDE activo")
sleep(0.5)
else:
led_verde.value(0)