Skip to content

Commit adf0418

Browse files
authored
Create led-fade.ino
1 parent 4ddb50f commit adf0418

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

led-fade.ino

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
int led = 9; // the pin that the LED is attached to
2+
int brightness = 0; // how bright the LED is
3+
int fadeAmount = 5; // how many points to fade the LED by
4+
5+
// the setup routine runs once when you press reset:
6+
void setup() {
7+
// declare pin 9 to be an output:
8+
pinMode(led, OUTPUT);
9+
}
10+
11+
// the loop routine runs over and over again forever:
12+
void loop() {
13+
// set the brightness of pin 9:
14+
analogWrite(led, brightness);
15+
16+
// change the brightness for next time through the loop:
17+
brightness = brightness + fadeAmount;
18+
19+
// reverse the direction of the fading at the ends of the fade:
20+
if (brightness == 0 || brightness == 255) {
21+
fadeAmount = -fadeAmount ;
22+
}
23+
// wait for 30 milliseconds to see the dimming effect
24+
delay(30);
25+
}

0 commit comments

Comments
 (0)