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 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); } }