from machine import Pin
from time import sleep

# LED pins
led_pins = [15, 2, 4, 5, 18, 19, 21, 22]
leds = [Pin(pin, Pin.OUT) for pin in led_pins]

# Button pins (with pull-up resistors)
entrance_button = Pin(13, Pin.IN, Pin.PULL_UP)
exit_button = Pin(14, Pin.IN, Pin.PULL_UP)

# Initial car count
car_count = 0

def update_leds(count):
    for i in range(8):
        leds[i].value(1 if i < count else 0)

while True:
    if entrance_button.value() == 0:  # Button pressed (active low)
        if car_count < 8:
            car_count += 1
            update_leds(car_count)
            print("Car entered. Total:", car_count)
        sleep(0.3)  # Debounce delay

    if exit_button.value() == 0:  # Button pressed
        if car_count > 0:
            car_count -= 1
            update_leds(car_count)
            print("Car exited. Total:", car_count)
        sleep(0.3)