- This example shows how to fade an LED on pin 9 using the analogWrite() function.
- The analogWrite() function uses PWM, so if you want to change the pin you're using, be sure to use another PWM capable pin.
- On most Arduino, the PWM pins are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.
Program:
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
void setup() // the setup routine runs once when you press reset:
{
pinMode(led, OUTPUT); // declare pin 9 to be an output:
}
void loop() // the loop routine runs over and over again forever:
{
analogWrite(led, brightness); // set the brightness of pin 9:
brightness = brightness + fadeAmount; // change the brightness for next time through the loop:
if (brightness <= 0 || brightness >= 255)
// reverse the direction of the fading at the ends of the fade:
{
fadeAmount = -fadeAmount;
}
delay(30); // wait for 30 milliseconds to see the dimming effect
}
……
"brightness এর মান ০ দিয়ে শুরু হয়ে ৫ (fadeAmount = 5) করে বাড়তে থাকে ৩০ মিলিসেকেন্ড অন্তর অন্তর। ২৫৫ হলে আবার ৫ করে কমতে থাকে, কমতে কমতে এর মান শুন্য হলে আবার ৫ করে বাড়তে থাকে,এভাবেই চলতে থাকবে forever."
"brightness এর মান ০ দিয়ে শুরু হয়ে ৫ (fadeAmount = 5) করে বাড়তে থাকে ৩০ মিলিসেকেন্ড অন্তর অন্তর। ২৫৫ হলে আবার ৫ করে কমতে থাকে, কমতে কমতে এর মান শুন্য হলে আবার ৫ করে বাড়তে থাকে,এভাবেই চলতে থাকবে forever."
No comments:
Post a Comment