|
|
|
|
LED Fade by BARRAGAN <http://barraganstudio.com> Demonstrates the use of PWM pins (analog output) by dimming a light (LED) from off to maximum intensity and back. Created 5 February 2004 Revised 26 January 2008 |
||
|
|
// LED Fade
// by BARRAGAN <http://barraganstudio.com>
int value = 0; // variable to keep the actual value
int ledpin = 0; // light connected to analog pin 0
void setup()
{
// nothing for setup
}
void loop()
{
for(value = 0 ; value <= 1023; value+=5) // fade in (from min to max)
{
analogWrite(ledpin, value); // sets the value (range from 0 to 1023)
delay(30); // waits for 30 milli seconds to see the dimming effect
}
for(value = 1023; value >=0; value-=5) // fade out (from max to min)
{
analogWrite(ledpin, value);
delay(30);
}
}
|
![]() |