from machine import Pin
import time
import sensor
LED_PINS = [4, 5, 13, 14, 16, 17, 18, 21]
BUTTON_IN_PIN = 34
BUTTON_OUT_PIN = 35
leds = []
for pin_number in LED_PINS:
led = Pin(pin_number, Pin.OUT)
leds.append(led)
button_in = Pin(BUTTON_IN_PIN, Pin.IN, Pin.PULL_UP)
button_out = Pin(BUTTON_OUT_PIN, Pin.IN, Pin.PULL_UP)
last_in_state = 1
last_out_state = 1
print("نظام الموقف البسيط جاهز للعمل!")
while True:
current_in_state = button_in.value()
current_out_state = button_out.value()
if last_in_state == 1 and current_in_state == 0:
print("تم الضغط على زر الدخول!")
sensor.add_one_car()
if last_out_state == 1 and current_out_state == 0:
print("تم الضغط على زر الخروج!")
sensor.remove_one_car()
number_of_cars = sensor.car_count
for i in range(8):
if i < number_of_cars:
leds[i].on()
else:
leds[i].off()
last_in_state = current_in_state
last_out_state = current_out_state
time.sleep_ms(50)