from machine import Pin
import time

LED_PINS = [15, 2, 4, 5, 13, 12, 14, 27]
BUTTON_ENTRANCE_PIN = 21
BUTTON_EXIT_PIN = 35

leds = [Pin(p, Pin.OUT) for p in LED_PINS]
button_entrance = Pin(BUTTON_ENTRANCE_PIN, Pin.IN)
button_exit = Pin(BUTTON_EXIT_PIN, Pin.IN)

car_count = 0
MAX_CARS = 8
MIN_CARS = 0

for i in range(MAX_CARS):
    leds[i].value(0)

while True:
    if button_entrance.value() == 1:
        time.sleep_ms(50)
        if button_entrance.value() == 1:
            if car_count < MAX_CARS:
                car_count += 1
                print(f"Car count: {car_count}")
                if car_count > 0:
                    leds[car_count - 1].value(1)
            while button_entrance.value() == 1:
                time.sleep_ms(10)

    elif button_exit.value() == 1:
        time.sleep_ms(50)
        if button_exit.value() == 1:
            if car_count > MIN_CARS:
                if car_count > 0:
                    leds[car_count - 1].value(0)
                car_count -= 1
                print(f"Car count: {car_count}")
            while button_exit.value() == 1:
                time.sleep_ms(10)

    time.sleep_ms(10)