from machine import Pin
import time
#the pins
led_pins = [2, 4, 13, 14, 16, 17, 21, 27]

leds = [] #setuo the leds
for pin in led_pins:
    led = Pin(pin, Pin.OUT)
    led.value(0)  # here i turn off the luds so it wont light up once i run (without clicking on buttons)
    leds.append(led)
#the buttons
#the turn on btn is green 
#the turn off btn is red
enter_button = Pin(35, Pin.IN, Pin.PULL_UP)  # the button that will turn on the leds
exit_button = Pin(34, Pin.IN, Pin.PULL_UP)   # turn off
# variables
counter = 0 # start with 0 cars

#funcitions
def car_count_screen(): # this funcition will show the number of cars (using the leds)
    global counter #edit
    for i in range(8):
        if i < counter:
            leds[i].value(1)  # turn on
        else:
            leds[i].value(0)  # turn off

#====== the loop ======

while True:
    # Check if "Enter" button is pressed and count is less than 8
    if enter_button.value() == 0 and counter < 8:
        counter += 1
        car_count_screen()
        print("Car entered. Total number of cars in the parking:", counter)#edit
        time.sleep(0.2)  # delay so the program wont lag

    


    if exit_button.value() == 0 and counter > 0: # when the exit btn is clicked and there is cars in the parking this will happen
        counter -= 1
        car_count_screen()
        print("Car exited. Total number of cars in the parking:", counter)#edit
        time.sleep(0.2)

    time.sleep(0.2)  # no lags


#================================================