from machine import Pin
from time import sleep
green = Pin(25, Pin.OUT)
red = Pin(26, Pin.OUT)
yellow = Pin(27, Pin.OUT)
blue = Pin(14, Pin.OUT)
entry_button = Pin(18, Pin.IN, Pin.PULL_UP)
exit_button = Pin(19, Pin.IN, Pin.PULL_UP)
car_count = 0
def update_status():
if car_count >= 15:
green.off()
red.on()
else:
green.on()
red.off()
green.on()
red.off()
yellow.off()
blue.off()
while True:
if entry_button.value() == 0:
if car_count < 15:
car_count += 1
yellow.on()
update_status()
sleep(1)
yellow.off()
while entry_button.value() == 0:
sleep(0.05)
if exit_button.value() == 0:
if car_count > 0:
car_count -= 1
blue.on()
update_status()
sleep(1)
blue.off()
while exit_button.value() == 0:
sleep(0.05)
sleep(0.05)