from machine import Pin
from time import sleep
led_pins = [2, 4, 5, 13, 14, 16, 17, 18]
leds = [Pin(pin, Pin.OUT) for pin in led_pins]
enter_button = Pin(34, Pin.IN, Pin.PULL_UP)
exit_button = Pin(35, Pin.IN, Pin.PULL_UP)
count = 0
def update_leds(n):
for i in range(8):
leds[i].value(1 if i < n else 0)
prev_enter = enter_button.value()
prev_exit = exit_button.value()
while True:
curr_enter = enter_button.value()
curr_exit = exit_button.value()
if curr_enter == 0 and prev_enter == 1:
if count < 8:
count += 1
update_leds(count)
sleep(0.1)
if curr_exit == 0 and prev_exit == 1:
if count > 0:
count -= 1
update_leds(count)
sleep(0.1)
prev_enter = curr_enter
prev_exit = curr_exit
sleep(0.01)