from machine import Pin
import time
MAX = 15
count = 0
in_btn = Pin(14, Pin.IN, Pin.PULL_UP)
out_btn = Pin(27, Pin.IN, Pin.PULL_UP)
green = Pin(2, Pin.OUT)
red = Pin(4, Pin.OUT)
yellow = Pin(5, Pin.OUT)
blue = Pin(18, Pin.OUT)
green.on()
while True:
if in_btn.value() == 0:
if count < MAX:
count += 1
print("Cars:", count)
yellow.on()
time.sleep(0.3)
yellow.off()
if count >= MAX:
green.off()
red.on()
while in_btn.value() == 0:
time.sleep(0.05)
if out_btn.value() == 0:
if count > 0:
count -= 1
print("Cars:", count)
blue.on()
time.sleep(0.2)
blue.off()
green.on()
red.off()
while out_btn.value() == 0:
time.sleep(0.01)