This example is for Wiring version 0024+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.
Fading in/out, controlling an LED Intensity by BARRAGAN
Demonstrates the use of PWM pins (analog output) by dimming a light (LED) from off to maximum intensity and back.
Demonstrates the use of PWM pins (analog output) by dimming a light (LED) from off to maximum intensity and back.
int ledpin = 37; // light connected to PWM pin 37
void setup()
{
// nothing for setup
}
void loop()
{
for(int 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(int value = 1023; value >=0; value-=5) // fade out (from max to min)
{
analogWrite(ledpin, value);
delay(30);
}
}


