from machine import Pin
import time
# Configuración de LEDs
leds = [
Pin(13, Pin.OUT), # LED izquierdo
Pin(14, Pin.OUT), # LED centro
Pin(15, Pin.OUT) # LED derecho
]
# Configuración de botones con PULL_UP interno
btn_left = Pin(16, Pin.IN, Pin.PULL_UP) # Botón izquierdo
btn_right = Pin(17, Pin.IN) # Botón derecho
# Función para encender los LEDs en una dirección
def secuencia_leds(led_list, delay=0.2):
for led in led_list:
led.value(1)
time.sleep(delay)
led.value(0)
print("LEFT: ", btn_left)
print("VALUE LEFT: ", btn_left.value())
print("RIGHT: ", btn_right)
print("VALUE RIGHT: ", btn_right.value())
while True:
left_pressed = btn_left.value() == 0 # 0 = presionado
right_pressed = btn_right.value() == 0
print("VALUE RIGHT: ", btn_right.value())
print("######### BOTONES ###########")
print("LEFT: ", left_pressed)
print("RIGHT: ", right_pressed)
print("#############################")
if left_pressed and right_pressed:
print("AMBOS")
for led in leds:
led.value(1)
while (btn_left.value() == 0) and (btn_right.value() == 0):
time.sleep(0.05)
for led in leds:
led.value(0)
elif left_pressed:
print("LEFT")
secuencia_leds(leds, 0.2)
elif right_pressed:
print("RIGHT")
secuencia_leds(reversed(leds), 0.2)
else:
print("NINGUNO")
# Si quieres que queden apagados cuando no presionas nada, comenta la siguiente línea:
secuencia_leds(leds, 0.2)