from machine import Pin
import time
# Los LEDs están en GP0, GP1, GP2, GP3, GP4, GP5, GP6, GP7, GP8, GP9
led_pins = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
leds = [Pin(p, Pin.OUT) for p in led_pins]
# Botones conectados a GP17 y GP18 (se me olvido que eran 16 y 18 y ya no quiero moverle por que ya funciono)
# Usamos PULL_UP porque el cable negro DEBE ir a GND
btn_arriba = Pin(17, Pin.IN, Pin.PULL_UP) #el boton de abajo retrocede hacia arriba
btn_abajo = Pin(18, Pin.IN, Pin.PULL_UP) #el boton de arriba hace que avance hacia abajo
posicion = 0
def actualizar_barra():
for i in range(10):
leds[i].value(1 if i == posicion else 0)
# Estado inicial
actualizar_barra()
while True:
# En PULL_UP, el valor es 0 cuando se presiona
if btn_arriba.value() == 0:
if posicion > 0:
posicion -= 1
actualizar_barra()
time.sleep(0.2) # Debounce
while btn_arriba.value() == 0: pass # Esperar a soltar
if btn_abajo.value() == 0:
if posicion < 9:
posicion += 1
actualizar_barra()
time.sleep(0.2) # Debounce
while btn_abajo.value() == 0: pass # Esperar a soltar
time.sleep(0.05)