from machine import Pin
from time import sleep
red=Pin(15,Pin.OUT)
blue=Pin(16,Pin.OUT)
yellow=Pin(17,Pin.OUT)
green=Pin(18,Pin.OUT)
blue_btn=Pin(12,Pin.IN,Pin.PULL_DOWN)
yellow_btn=Pin(14,Pin.IN,Pin.PULL_DOWN)
counter = 0
green.on()
red.off()
while True:
if yellow_btn.value() == 1:
if counter < 15:
counter = counter + 1
print("Car entered. Count:", counter)
yellow.on()
sleep(0.2)
yellow.off()
if counter == 15:
green.off()
red.on()
sleep(0.3)
if blue_btn.value() == 1:
if counter > 0:
counter = counter - 1
print("Car exited. Count:", counter)
blue.on()
sleep(0.2)
blue.off()
if counter < 15:
green.on()
red.off()
sleep(0.3)