from machine import Pin
import time
led_pins = [13, 12, 14, 27, 26, 25, 33, 32]
lights = [Pin(pin, Pin.OUT) for pin in led_pins]
button_increment = Pin(4, Pin.IN, Pin.PULL_UP)
button_decrement = Pin(5, Pin.IN, Pin.PULL_UP)
ledCount = 0
debounce_delay_ms = 200
last_increment_press_time = 0
last_decrement_press_time = 0
def upd():
for i in range(len(lights)):
if i < lit_led_count:
lights[i].value(1)
else:
lights[i].value(0)
lights[i].value(0)
while True:
current = time.ticks_ms()
if button_increment.value() == 0 and (current - last_increment_press_time) > debounce_delay_ms:
if lit_led_count < len(lights):
lit_led_count += 1
upd()
last_increment_press_time = current
if button_decrement.value() == 0 and (current_time_ms - last_decrement_press_time) > debounce_delay_ms:
if lit_led_count > 0:
lit_led_count -= 1
upd()
last_decrement_press_time = current_time_ms
time.sleep_ms(10)