4
This example shows how to fade an LED using the analogWrite() function.
7
* LED attached from digital pin 9 to ground.
14
http://arduino.cc/en/Tutorial/Fading
16
This example code is in the public domain.
21
int ledPin = 9; // LED connected to digital pin 9
24
// nothing happens in setup
28
// fade in from min to max in increments of 5 points:
29
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
30
// sets the value (range from 0 to 255):
31
analogWrite(ledPin, fadeValue);
32
// wait for 30 milliseconds to see the dimming effect
36
// fade out from max to min in increments of 5 points:
37
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
38
// sets the value (range from 0 to 255):
39
analogWrite(ledPin, fadeValue);
40
// wait for 30 milliseconds to see the dimming effect