| 1 |
/* |
| 2 |
Mega analogWrite() test |
| 3 |
|
| 4 |
This sketch fades LEDs up and down one at a time on digital pins 2 through 13. |
| 5 |
This sketch was written for the Arduino Mega, and will not work on other boards. |
| 6 |
|
| 7 |
The circuit: |
| 8 |
- LEDs attached from pins 2 through 13 to ground. |
| 9 |
|
| 10 |
created 8 Feb 2009 |
| 11 |
by Tom Igoe |
| 12 |
|
| 13 |
This example code is in the public domain. |
| 14 |
|
| 15 |
https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogWriteMega |
| 16 |
*/ |
| 17 |
|
| 18 |
// These constants won't change. They're used to give names to the pins used: |
| 19 |
const int lowestPin = 2; |
| 20 |
const int highestPin = 13; |
| 21 |
|
| 22 |
|
| 23 |
void setup() { |
| 24 |
// set pins 2 through 13 as outputs: |
| 25 |
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) { |
| 26 |
pinMode(thisPin, OUTPUT); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
void loop() { |
| 31 |
// iterate over the pins: |
| 32 |
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) { |
| 33 |
// fade the LED on thisPin from off to brightest: |
| 34 |
for (int brightness = 0; brightness < 255; brightness++) { |
| 35 |
analogWrite(thisPin, brightness); |
| 36 |
delay(2); |
| 37 |
} |
| 38 |
// fade the LED on thisPin from brightest to off: |
| 39 |
for (int brightness = 255; brightness >= 0; brightness--) { |
| 40 |
analogWrite(thisPin, brightness); |
| 41 |
delay(2); |
| 42 |
} |
| 43 |
// pause between LEDs: |
| 44 |
delay(100); |
| 45 |
} |
| 46 |
} |