from machine import Pin, PWM
import time
# ===== LEDs حرف A =====
A_leds = [
Pin(8, Pin.OUT),
Pin(9, Pin.OUT),
Pin(11, Pin.OUT),
Pin(10, Pin.OUT),
Pin(15, Pin.OUT),
Pin(12, Pin.OUT)
]
# ===== LEDs حرف S =====
S_leds = [
Pin(0, Pin.OUT),
Pin(1, Pin.OUT),
Pin(2, Pin.OUT),
Pin(3, Pin.OUT),
Pin(4, Pin.OUT),
Pin(5, Pin.OUT),
Pin(6, Pin.OUT),
Pin(7, Pin.OUT),
]
# ===== LEDs زرق =====
blue_leds = [
PWM(Pin(3)),
PWM(Pin(4)),
PWM(Pin(5)),
PWM(Pin(6)),
PWM(Pin(7)),
PWM(Pin(8)),
PWM(Pin(9)),
PWM(Pin(11))
]
# ===== LEDs حمر =====
red_leds = [
PWM(Pin(0)),
PWM(Pin(1)),
PWM(Pin(2)),
PWM(Pin(10)),
PWM(Pin(12)),
PWM(Pin(15))
]
for led in blue_leds + red_leds:
led.freq(1000)
# ===== RGB =====
rgb_r = Pin(28, Pin.OUT)
rgb_g = Pin(27, Pin.OUT)
rgb_b = Pin(26, Pin.OUT)
colors = [(1,0,0),(1,1,0),(1,0,1),(0,0,1)]
ci = 0
def rgb_set(c):
rgb_r.value(c[0])
rgb_g.value(c[1])
rgb_b.value(c[2])
# ===== الأزرار =====
button_A = Pin(16, Pin.IN, Pin.PULL_DOWN)
button_S = Pin(13, Pin.IN, Pin.PULL_DOWN)
button_blue = Pin(22, Pin.IN, Pin.PULL_DOWN)
button_red = Pin(21, Pin.IN, Pin.PULL_DOWN)
button_all = Pin(20, Pin.IN, Pin.PULL_DOWN)
# ===== إطفاء الكل =====
def turn_off_all():
for led in A_leds + S_leds:
led.value(0)
for led in blue_leds + red_leds:
led.duty_u16(0)
# ===== حرف A =====
def show_A():
turn_off_all()
print("ASEEL")
for led in A_leds:
led.value(1)
# ===== حرف S =====
def show_S():
turn_off_all()
print("QRATEM")
for led in S_leds:
led.value(1)
# ===== تأثير تدريجي =====
def fade_leds(led_list):
for i in range(0, 65535, 2000):
for led in led_list:
led.duty_u16(i)
time.sleep(0.01)
time.sleep(0.3)
for i in range(65535, 0, -2000):
for led in led_list:
led.duty_u16(i)
time.sleep(0.01)
turn_off_all()
# ===== تشغيل الكل =====
def all_on():
for led in A_leds + S_leds:
led.value(1)
for led in blue_leds + red_leds:
led.duty_u16(65535)
# ===== البرنامج الرئيسي =====
while True:
if button_A.value() == 1:
show_A()
time.sleep(0.3)
elif button_S.value() == 1:
show_S()
time.sleep(0.3)
elif button_blue.value():
fade_leds(blue_leds)
time.sleep(0.3)
elif button_red.value():
fade_leds(red_leds)
time.sleep(0.3)
elif button_all.value():
all_on()
# 🌈 RGB يرمش دايمًا
rgb_set(colors[ci])
ci = (ci + 1) % len(colors)
time.sleep(0.5)