from machine import Pin
from time import sleep
# تعريف دبابيس الـ LED
led_pins = [2, 4, 5, 13, 14, 18, 19, 21]
leds = [Pin(pin, Pin.OUT) for pin in led_pins]
# تعريف زر الدخول وزر الخروج مع Pull-Up
entrance_btn = Pin(34, Pin.IN, Pin.PULL_UP)
exit_btn = Pin(35, Pin.IN, Pin.PULL_UP)
# العداد
car_count = 0
MAX_CARS = 8
# حالات الأزرار السابقة لتجنب العد المكرر
prev_entrance = 1
prev_exit = 1
# تحديث إضاءة الليدات حسب عدد العربيات
def update_leds(count):
for i in range(8):
leds[i].value(1 if i < count else 0)
while True:
# قراءة حالة الأزرار
current_entrance = entrance_btn.value()
current_exit = exit_btn.value()
# إذا تم الضغط على زر الدخول
if current_entrance == 0 and prev_entrance == 1:
if car_count < MAX_CARS:
car_count += 1
update_leds(car_count)
sleep(0.2)
# إذا تم الضغط على زر الخروج
if current_exit == 0 and prev_exit == 1:
if car_count > 0:
car_count -= 1
update_leds(car_count)
sleep(0.2)
# تحديث الحالة السابقة للأزرار
prev_entrance = current_entrance
prev_exit = current_exit