تلاشي إضاءة مصباح LED صعودًا وهبوطًا
التكرار عبر القيم لإحداث تأثير ضوء يتنفس
تلاشي إضاءة مصباح LED صعودًا وهبوطًا درس مجاني في Arduino & IoT Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Arduino & IoT Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
From Steady to Breathing
One fixed value gives a steady glow. To make an LED fade, you simply keep changing the analogWrite value over time. 🌬️
The Plan: Count Up Slowly
To fade in, walk the brightness from 0 toward 255 in small steps, pausing briefly between each one so the change is visible.
A Loop That Climbs
A for loop is perfect for stepping through values. It counts from 0 to 255 and writes each one to the LED pin.
for (int b = 0; b <= 255; b++) {
analogWrite(9, b);
delay(10);
}delay Sets the Speed
The delay inside the loop controls how fast the fade feels. A bigger pause makes a slower, gentler rise.
delay(10); // 10 ms per stepNow Fade Back Down
To fade out, run a second loop that counts the brightness back down from 255 to 0, again pausing each step.
for (int b = 255; b >= 0; b--) {
analogWrite(9, b);
delay(10);
}Put Both in loop()
Place the up loop then the down loop inside loop. Arduino repeats loop forever, so you get an endless breathing effect.
Step Size Changes the Feel
Counting by 1 is silky smooth. Increase the step to b += 5 and the fade speeds up but turns slightly choppy.
for (int b = 0; b <= 255; b += 5)Stay Inside the Range
Keep your counter between 0 and 255. Writing values outside that range just wraps or clamps and breaks the smooth ramp.
An Alternative: One Variable
Instead of two loops, keep one brightness variable and a direction. Add or subtract each pass and flip direction at the ends.
brightness += direction;
if (brightness == 0 || brightness == 255)
direction = -direction;Use a PWM Pin
This only fades on a PWM pin like 9. On a plain pin the LED would jump straight from off to on with no smooth ramp.
Why It Looks So Calm
The breathing look works because each small step nudges the duty cycle a little, and your eye averages the tiny changes.
Quick Check
Think about what makes a fade smooth.
Recap: Make It Breathe
Step the brightness from 0 to 255 and back with small delays. Loop it forever on a PWM pin and your LED breathes. ✨
الأسئلة الشائعة
هل درس «تلاشي إضاءة مصباح LED صعودًا وهبوطًا» مجاني؟
نعم — نص درس «تلاشي إضاءة مصباح LED صعودًا وهبوطًا» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Arduino & IoT Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.
ماذا ستتعلم في «تلاشي إضاءة مصباح LED صعودًا وهبوطًا»؟
التكرار عبر القيم لإحداث تأثير ضوء يتنفس تتمرن على Arduino & IoT Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Arduino & IoT Academy؟
لا تُشترط خبرة سابقة. Arduino & IoT Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «تلاشي إضاءة مصباح LED صعودًا وهبوطًا»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Arduino & IoT Academy هذا؟
نعم. كل درس في Arduino & IoT Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- ما الذي يفعله PWM فعلًا
- analogWrite من 0 إلى 255
- تلاشي إضاءة مصباح LED صعودًا وهبوطًا
- المقبض يتحكم في سطوع مصباح LED