from machine import Pin
import time
# Define LED pins based on your actual Wokwi circuit
led_pins = [13, 12, 14, 27, 26, 25, 33, 32]
leds = [Pin(p, Pin.OUT) for p in led_pins]
# Define button pins (Entrance = GPIO 4, Exit = GPIO 2)
entrance_button = Pin(34, Pin.IN, Pin.PULL_UP)
exit_button = Pin(35, Pin.IN, Pin.PULL_UP)
car_count = 0 # Counter for cars inside (0 to 8)
def update_leds():
for i in range(8):
leds[i].value(1 if i < car_count else 0)
def turn_off_all_leds():
for led in leds:
led.value(0)
print("Car monitoring system starting...")
turn_off_all_leds()
while True:
if entrance_button.value() == 0:
if car_count < 8:
car_count += 1
print(f"Car entered. Current count: {car_count}")
update_leds()
else:
print("Maximum car capacity reached (8). No more cars can enter.")
time.sleep(0.3)
if exit_button.value() == 0:
if car_count > 0:
car_count -= 1
print(f"Car exited. Current count: {car_count}")
update_leds()
else:
print("No cars inside. No more cars can exit.")
time.sleep(0.3)
time.sleep(0.01)