from machine import Pin
import time
# Inputs
btn_entry = Pin(33, Pin.IN, Pin.PULL_DOWN)
btn_exit = Pin(13, Pin.IN, Pin.PULL_DOWN)
# Outputs
led_green = Pin(21, Pin.OUT)
led_red = Pin(2, Pin.OUT)
led_yellow = Pin(16, Pin.OUT)
led_blue = Pin(0, Pin.OUT)
cars = 0
# Led Status
led_green.value(1)
led_red.value(0)
led_yellow.value(0)
led_blue.value(0)
print("System Loaded! Cars Count:", cars)
while True:
# Entry Button (Top Button)
if btn_entry.value() == 1:
if cars < 15:
cars = cars + 1
print("Car Entered. Count:", cars)
# Update State LEDs Status First
if cars == 15:
led_green.value(0)
led_red.value(1)
else:
led_green.value(1)
led_red.value(0)
# Blink Yellow Event LED
led_yellow.value(1)
time.sleep(0.2)
led_yellow.value(0)
time.sleep(0.3)
else:
print("Garage Is Already Full! Entry Is ignored.")
time.sleep(0.3)
# Exit Button (Bottom Button)
if btn_exit.value() == 1:
if cars > 0:
cars = cars - 1
print("Car Exited. Count:", cars)
# Update State LEDs Status First
if cars == 15:
led_green.value(0)
led_red.value(1)
else:
led_green.value(1)
led_red.value(0)
# Blink Blue Event LED
led_blue.value(1)
time.sleep(0.2)
led_blue.value(0)
time.sleep(0.3)
else:
print("Garage Is Already Empty! Exit Is ignored.")
time.sleep(0.3)
time.sleep(0.05)