from machine import Pin
from time import sleep
red = Pin(2, Pin.OUT)
blue = Pin(4, Pin.OUT)
green = Pin(5, Pin.OUT)
yellow = Pin(18, Pin.OUT)
entry = Pin(26, Pin.IN, Pin.PULL_UP)
exit_button = Pin(27, Pin.IN, Pin.PULL_UP)
cars = 0
capacity = 15
green.on()
red.off()
yellow.off()
blue.off()
while True:
if entry.value() == 0:
if cars < capacity:
cars += 1
yellow.on()
sleep(0.3)
yellow.off()
if cars == 15:
green.off()
red.on()
else:
green.on()
red.off()
print("Entry accepted")
print("Cars:", cars)
while entry.value() == 0:
sleep(0.05)
if exit_button.value() == 0:
if cars > 0:
cars -= 1
blue.on()
sleep(0.3)
blue.off()
if cars == 15:
green.off()
red.on()
else:
green.on()
red.off()
print("Exit accepted")
print("Cars:", cars)
while exit_button.value() == 0:
sleep(0.05)
sleep(0.05)Loading
esp32-devkit-c-v4
esp32-devkit-c-v4