from machine import Pin
from time import sleep
entrance_button = Pin(34, Pin.IN, Pin.PULL_DOWN)
exit_button = Pin(35, Pin.IN, Pin.PULL_DOWN)
led_pins = [2, 13, 14, 27, 18, 17, 16, 21]
leds = [Pin(pin, Pin.OUT) for pin in led_pins]
car_count = 0
max_count = 8
min_count = 0
prv_entrance = 0
prv_exit = 0
def update_leds(count):
for i in range(8):
if i < count:
leds[i].value(1)
else:
leds[i].value(0)
while True:
entrance_state = entrance_button.value()
exit_state = exit_button.value()
if entrance_state == 1 and prv_entrance == 0:
if car_count < max_count:
car_count += 1
update_leds(car_count)
print("Car Entered. Count:", car_count)
sleep(0.2)
if exit_state == 1 and prv_exit == 0:
if car_count > min_count:
car_count -= 1
update_leds(car_count)
print("Car Exited. Count:", car_count)
sleep(0.2)
prv_entrance = entrance_state
prv_exit = exit_state
sleep(0.2)