from machine import Pin
from time import sleep
green = Pin(25, Pin.OUT)
yellow = Pin(26, Pin.OUT)
red = Pin(27, Pin.OUT)
enter = Pin(19, Pin.IN, Pin.PULL_UP)
exit = Pin(18, Pin.IN, Pin.PULL_UP)
cars = 0
MAX_CARS = 15
def update_leds():
if cars <= 10:
green.on()
yellow.off()
red.off()
elif cars <= 14:
green.off()
yellow.on()
red.off()
else:
green.off()
yellow.off()
red.on()
update_leds()
while True:
if enter.value() == 0:
if cars < MAX_CARS:
cars += 1
print("Car Entered")
print("Cars =", cars)
else:
print("Parking Full!")
update_leds()
while enter.value() == 0:
sleep(.01)
sleep(0.3)
if exit.value() == 0:
if cars > 0:
cars -= 1
print("Car Exited")
print("Cars =", cars)
else:
print("Parking Empty!")
update_leds()
while exit.value() == 0:
sleep(.01)
sleep(0.3)