4
This example shows how to fade an LED on pin 9
5
using the analogWrite() function.
7
This example code is in the public domain.
10
int brightness = 0; // how bright the LED is
11
int fadeAmount = 5; // how many points to fade the LED by
14
// declare pin 9 to be an output:
19
// set the brightness of pin 9:
20
analogWrite(9, brightness);
22
// change the brightness for next time through the loop:
23
brightness = brightness + fadeAmount;
25
// reverse the direction of the fading at the ends of the fade:
26
if (brightness == 0 || brightness == 255) {
27
fadeAmount = -fadeAmount ;
29
// wait for 30 milliseconds to see the dimming effect