/* Fade This example shows how to fade an LED on pin 10 using the analogWrite() function. This example code is in the public domain. */ int led = 10; // the pin that 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() { // declare pin 10 to be an output: pinMode (led, OUTPUT); } void loop() { // set the brightness of pin 10: analogWrite (led, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if ( brightness ==0 || brightness ==255){ fadeAmount =-fadeAmount ; } // wait for 40 milliseconds to see the dimming effect delay (40); }