from machine import Pin
import time
pins = [2, 4, 5, 16, 17, 18, 21, 27]
led_array = [Pin(p, Pin.OUT) for p in pins]
in_button = Pin(34, Pin.IN)
out_button = Pin(35, Pin.IN)
car_count = 0
def show_leds(count):
for idx in range(8):
led_array[idx].value(1 if idx < count else 0)
last_in = 1
last_out = 1
while True:
current_in = in_button.value()
current_out = out_button.value()
if current_in == 0 and last_in == 1 and car_count < 8:
car_count += 1
show_leds(car_count)
time.sleep(0.01)
if current_out == 0 and last_out == 1 and car_count > 0:
car_count -= 1
show_leds(car_count)
time.sleep(0.01)
last_in = current_in
last_out = current_out
time.sleep(0.01)