4 This example shows how to fade an LED on pin 9
5 using the analogWrite() function.
6 This example code is in the public domain.
7 From Arduino for dummies.
11 int brightness = 0; // this two could be bytes as well
13 // the pin that the LED is attached to
14 // how bright the LED is
15 // how many points to fade the LED by
16 // the setup routine runs once when you press reset:
19 // declare pin 9 to be an output:
22 // the loop routine runs over and over again forever:
24 // set the brightness of pin 9:
25 analogWrite(led, brightness);
26 // change the brightness for next time through the loop:
27 brightness = brightness + fadeAmount;
28 // reverse the direction of the fading at the ends of the fade:
29 if (brightness == 0 || brightness == 255) {
30 fadeAmount = -fadeAmount ;
32 // wait for 30 milliseconds to see the dimming effect
33 delay(30); // Question: should this value be here?
34 // Would it be better to have a variable for it? Why?