from machine import Pin
from time import sleep
# LEDs
Yellow = Pin(19, Pin.OUT)
Green = Pin(15, Pin.OUT)
Blue = Pin(13, Pin.OUT)
Red = Pin(12, Pin.OUT)
#Buttons
Enter_button = Pin(25, Pin.IN, Pin.PULL_DOWN)
Exit_button = Pin(26, Pin.IN, Pin.PULL_DOWN)
#Variables
Enter_last_state = 0
Exit_last_state = 0
Cars = 0
MAX_CARS = 15
def update_parking_leds():
if Cars == MAX_CARS:
Red.on()
Green.off()
else:
Red.off()
Green.on()
# Initial LED status
update_parking_leds()
while True:
Enter_state = Enter_button.value()
Exit_state = Exit_button.value()
if Enter_state == 1 and Enter_last_state == 0 and Cars < MAX_CARS:
sleep(0.8)
Yellow.on()
sleep(0.8)
Yellow.off()
sleep(0.8)
Cars = Cars+1
update_parking_leds()
if Exit_state == 1 and Exit_last_state == 0 and Cars > 0:
sleep(0.8)
Blue.on()
sleep(0.8)
Blue.off()
sleep(0.8)
Cars = Cars-1
update_parking_leds()
Enter_last_state = Enter_state
sleep(0.5)
Exit_last_state = Exit_state
sleep(0.5)