from machine import Pin
from time import sleep
print("Press the first and second buttons to select a pizza slice,")
print(" then press the last button to prepare it.")
# تعريف الأزرار
button1 = Pin(22, Pin.IN, Pin.PULL_DOWN)
button2 = Pin(21, Pin.IN, Pin.PULL_DOWN)
button3 = Pin(20, Pin.IN, Pin.PULL_DOWN)
# تعريف الـ LEDs الأساسية
red = Pin(26, Pin.OUT)
green = Pin(27, Pin.OUT)
blue = Pin(28, Pin.OUT)
ready_led = Pin(25, Pin.OUT)
# تعريف الـ RGB (تأكد من عدم تكرار الـ Pins مع الليدات الأخرى)
red1 = Pin(23, Pin.OUT) # تم تغيير Pin 5 لمنع التضارب مع L6
green1 = Pin(16, Pin.OUT)
blue1 = Pin(17, Pin.OUT)
red2 = Pin(13, Pin.OUT)
green2 = Pin(18, Pin.OUT)
blue2 = Pin(19, Pin.OUT)
# تعريف ليدات البيتزا (المجموعة 1)
L1=Pin(0,Pin.OUT)
L2=Pin(1,Pin.OUT)
L3=Pin(2,Pin.OUT)
L4=Pin(3,Pin.OUT)
L5=Pin(4,Pin.OUT)
L6=Pin(5,Pin.OUT)
L7=Pin(6,Pin.OUT)
L8=Pin(7,Pin.OUT)
# L15 تم حذف تكرارها وربطها بـ Pin جديد إذا لزم الأمر أو حذفها
L15=Pin(24, Pin.OUT)
# تعريف ليدات البيتزا (المجموعة 2)
L17=Pin(8,Pin.OUT)
L18=Pin(9,Pin.OUT)
L19=Pin(10,Pin.OUT)
L20=Pin(11,Pin.OUT)
L21=Pin(12,Pin.OUT)
# L22 و L23 و L24 تم تعديلها لتجنب التضارب مع RGB pins (13, 18, 19)
L22=Pin(14,Pin.OUT)
L23=Pin(15,Pin.OUT)
L24=Pin(30,Pin.OUT) # تأكد من استخدام Pin متاح في بوردتك
def set_color2(r, g, b):
red1.value(r)
green1.value(g)
blue1.value(b)
def set_color3(r, g, b):
red2.value(r)
green2.value(g)
blue2.value(b)
# تصفير جميع الليدات عند البداية
def clear_all():
for pin in [L1,L2,L3,L4,L5,L6,L7,L8,L15,L17,L18,L19,L20,L21,L22,L23,L24,red,green,blue,ready_led]:
pin.value(0)
set_color2(0,0,0)
set_color3(0,0,0)
clear_all()
while True:
# --- اختيار البيتزا الأولى (Toggle) ---
if button1.value() == 1:
# استخدام خاصية التوقل مباشرة
L1.toggle(); L2.toggle(); L3.toggle(); L4.toggle()
L5.toggle(); L6.toggle(); L7.toggle(); L8.toggle(); L15.toggle()
if L1.value() == 1:
set_color2(1,1,0) # أصفر عند التفعيل
print("One slice of pepperoni was chosen")
else:
set_color2(0,0,0) # إطفاء عند الإلغاء
print("Pepperoni selection removed")
sleep(0.3) # منع الارتداد (Debounce)
# --- اختيار البيتزا الثانية (Toggle) ---
if button2.value() == 1:
L17.toggle(); L18.toggle(); L19.toggle(); L20.toggle()
L21.toggle(); L22.toggle(); L23.toggle(); L24.toggle()
if L17.value() == 1:
set_color3(1,1,0)
print("One slice of vegetable was chosen")
else:
set_color3(0,0,0)
print("Vegetable selection removed")
sleep(0.3)
# --- عملية التحضير (Button 3) ---
if button3.value() == 1:
if L1.value() == 0 and L17.value() == 0:
print("Warning: Please select a pizza first!")
for _ in range(3): # وميض أحمر للتنبيه
red.value(1); sleep(0.2); red.value(0); sleep(0.2)
else:
print("Starting Cook...")
# محاكاة الطبخ
blue.value(1); sleep(1); blue.value(0)
red.value(1); sleep(1); red.value(0)
ready_led.value(1)
print("Pizza is Ready!")
sleep(3)
# إعادة ضبط النظام بعد الانتهاء
clear_all()
sleep(0.1)