from machine import Pin
import time
led_pins = [Pin(i, Pin.OUT) for i in [2, 4, 16, 17, 5, 18, 13, 14]]
btn_entrance = Pin(35, Pin.IN, Pin.PULL_UP)
btn_exit = Pin(34, Pin.IN, Pin.PULL_UP)
count = 0
last_press_time = 0
def update_leds():
for i in range(8):
led_pins[i].value(1 if i < count else 0)
def entrance_handler(pin):
global count, last_press_time
if time.ticks_ms() - last_press_time > 300:
if count < 8:
count += 1
update_leds()
last_press_time = time.ticks_ms()
def exit_handler(pin):
global count, last_press_time
if time.ticks_ms() - last_press_time > 300:
if count > 0:
count -= 1
update_leds()
last_press_time = time.ticks_ms()
btn_entrance.irq(trigger=Pin.IRQ_FALLING, handler=entrance_handler)
btn_exit.irq(trigger=Pin.IRQ_FALLING, handler=exit_handler)
while True:
time.sleep(1)