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]
entrance_button = Pin(34, Pin.IN)
exit_button = Pin(35, Pin.IN)
car_count = 0
def update_leds(count):
for i in range(8):
leds[i].value(1 if i < count else 0)
prev_entrance = 0
prev_exit = 0
while True:
entrance = entrance_button.value()
exit = exit_button.value()
if entrance == 1 and prev_entrance == 0:
if car_count < 8:
car_count += 1
update_leds(car_count)
sleep(0.2)
if exit == 1 and prev_exit == 0:
if car_count > 0:
car_count -= 1
update_leds(car_count)
sleep(0.2)
prev_entrance = entrance
prev_exit = exit
sleep(0.05)