SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | Fade | |
3 | This example shows how to fade an LED on pin 9 | |
4 | using the analogWrite() function. | |
5 | This example code is in the public domain. | |
6 | */ | |
7 | int brightness = 0; // how bright the LED is | |
8 | int fadeAmount = 1; // how many points to fade the LED by | |
9 | int LEDpin = 10; | |
10 | ||
11 | void setup() { | |
12 | // declare pin 6 to be an output: | |
13 | pinMode(LEDpin, OUTPUT); | |
14 | Serial.begin(9600);// initialize the Serial communication | |
15 | } | |
16 | ||
17 | void loop() { | |
18 | // set the brightness of pin 6: | |
19 | analogWrite(LEDpin, brightness); | |
20 | ||
21 | // change the brightness for next time through the loop: | |
22 | brightness = brightness + fadeAmount; | |
23 | Serial.println(brightness); | |
24 | // reverse the direction of the fading at the ends of the fade: | |
25 | if (brightness <= 0 || brightness >= 255) { | |
26 | ||
27 | if(brightness >= 255){ | |
28 | Serial.println("Lets chill for a second"); | |
29 | delay(1000); | |
30 | } | |
31 | ||
32 | fadeAmount = -fadeAmount ; | |
33 | brightness = brightness + fadeAmount; | |
34 | } | |
35 | // wait for 30 milliseconds to see the dimming effect | |
36 | //delay(100); | |
37 | } |