from machine import Pin
import time
btn_entry = Pin(12, Pin.IN, Pin.PULL_DOWN)
btn_exit = Pin(14, Pin.IN, Pin.PULL_DOWN)
led_green = Pin(2, Pin.OUT)
led_red = Pin(4, Pin.OUT)
led_yellow = Pin(16, Pin.OUT)
led_blue = Pin(17, Pin.OUT)
car_count = 0
MAX_CAPACITY = 15
def update_state_leds():
if car_count == MAX_CAPACITY:
led_red.value(1)
led_green.value(0)
else:
led_red.value(0)
led_green.value(1)
update_state_leds()
while True:
if btn_entry.value() == 1:
if car_count < MAX_CAPACITY:
car_count += 1
print(f"Accepted Entry. Total cars: {car_count}")
led_yellow.value(1)
time.sleep(0.2)
led_yellow.value(0)
else:
print("Ignored Press: Garage Full (15)")
update_state_leds()
time.sleep(0.3)
if btn_exit.value() == 1:
if car_count > 0:
car_count -= 1
print(f"Accepted Exit. Total cars: {car_count}")
led_blue.value(1)
time.sleep(0.2)
led_blue.value(0)
else:
print("Ignored Press: Garage Empty (0)")
update_state_leds()
time.sleep(0.3)
time.sleep(0.05)