from machine import Pin
from time import sleep
# Pin configuration
ir_sensor = Pin(2, Pin.IN) # IR sensor pin
green_led = Pin(3, Pin.OUT) # Green LED (blinks on every entry)
reset_button = Pin(4, Pin.IN) # Reset button
capacity = 0
current_count = 0
# Set hall capacity
while capacity <= 0:
print("Please enter the event hall capacity: ")
capacity = int(input())
if capacity <= 0:
print("Capacity must be a positive number. Please try again.")
print("Event hall capacity is set to", capacity)
print("Visitor Counter is ready!")
printed_full_msg = False
while True:
# Check for reset only when hall is full
if current_count >= capacity:
if reset_button.value() == 1:
current_count = 0
printed_full_msg = False
print("Visitor counter reset! System ready for new entries.")
sleep(0.3) # Debounce delay
# Entrance Logic
if current_count < capacity and ir_sensor.value() == 1:
current_count += 1
print("Current Count:", current_count, "/", capacity)
# Blink green LED once
green_led.on()
sleep(0.1)
green_led.off()
sleep(0.1)
# Reset full message flag in case hall was previously full
printed_full_msg = False
# Wait until IR clears
while ir_sensor.value() == 1:
sleep(0.05)
# Show FULL message only once
if current_count >= capacity and not printed_full_msg:
print("Event hall is FULL! Press Reset Button to continue.")
printed_full_msg = True
sleep(0.1)