2009-07-11 02:34:59 +02:00
|
|
|
/*
|
|
|
|
Mega analogWrite() test
|
2013-10-21 09:58:40 +02:00
|
|
|
|
|
|
|
This sketch fades LEDs up and down one at a time on digital pins 2 through 13.
|
2017-07-12 19:58:31 +02:00
|
|
|
This sketch was written for the Arduino Mega, and will not work on other boards.
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2009-07-11 02:34:59 +02:00
|
|
|
The circuit:
|
2017-07-12 21:30:49 +02:00
|
|
|
- LEDs attached from pins 2 through 13 to ground.
|
2009-07-11 02:34:59 +02:00
|
|
|
|
|
|
|
created 8 Feb 2009
|
|
|
|
by Tom Igoe
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2010-02-23 19:59:41 +01:00
|
|
|
This example code is in the public domain.
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-12 22:18:23 +02:00
|
|
|
http://www.arduino.cc/en/Tutorial/AnalogWriteMega
|
2017-07-15 00:35:58 +02:00
|
|
|
*/
|
2017-07-12 22:18:23 +02:00
|
|
|
|
2017-07-13 10:01:49 +02:00
|
|
|
// These constants won't change. They're used to give names
|
2009-07-11 02:34:59 +02:00
|
|
|
// to the pins used:
|
|
|
|
const int lowestPin = 2;
|
|
|
|
const int highestPin = 13;
|
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
// set pins 2 through 13 as outputs:
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
|
|
|
|
pinMode(thisPin, OUTPUT);
|
2009-07-11 02:34:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
// iterate over the pins:
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
|
2009-07-11 02:34:59 +02:00
|
|
|
// fade the LED on thisPin from off to brightest:
|
|
|
|
for (int brightness = 0; brightness < 255; brightness++) {
|
|
|
|
analogWrite(thisPin, brightness);
|
|
|
|
delay(2);
|
2013-10-21 09:58:40 +02:00
|
|
|
}
|
2017-07-12 19:58:31 +02:00
|
|
|
// fade the LED on thisPin from brightest to off:
|
2009-07-11 02:34:59 +02:00
|
|
|
for (int brightness = 255; brightness >= 0; brightness--) {
|
|
|
|
analogWrite(thisPin, brightness);
|
|
|
|
delay(2);
|
2013-10-21 09:58:40 +02:00
|
|
|
}
|
2009-07-11 02:34:59 +02:00
|
|
|
// pause between LEDs:
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
}
|