from machine import Pin
from time import sleep
# Define LED pins (slot indicators)
led_pins = [15, 2, 0, 4, 16, 17, 5, 18]
leds = [Pin(pin, Pin.OUT) for pin in led_pins]
# Define buttons
btn1 = Pin(34, Pin.IN) # Entry button
btn2 = Pin(35, Pin.IN) # Exit button
car_count = 0 # Start with 0 cars
while True:
if btn1.value() == 1:
print("Button 1 pressed (Entry)")
if car_count < 8:
leds[car_count].value(1)
car_count += 1
print("Car entered. Total cars:", car_count)
else:
print("Parking Full! No available slots.")
sleep(0.3) # Debounce
if btn2.value() == 1:
print("Button 2 pressed (Exit)")
if car_count > 0:
car_count -= 1
leds[car_count].value(0)
print("Car exited. Total cars:", car_count)
else:
print("Parking Empty! No cars to exit.")
sleep(0.3) # Debounce