/*
Mega analogWrite() test
This sketch fades LEDs up and down one at a time on digital pins 2 through 13.
This sketch was written for the Arduino Mega, and will not work on other boards.
The circuit:
- LEDs attached from pins 2 through 13 to ground.
created 8 Feb 2009
by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogWriteMega
*/// These constants won't change. They're used to give names to the pins used:
constintlowestPin=2;constinthighestPin=13;
int型の変数lowestPinとhighestPinを定義し、それぞれ2と13初期化します。
setup()
23
24
25
26
27
28
29
voidsetup(){// set pins 2 through 13 as outputs:
for(intthisPin=lowestPin;thisPin<=highestPin;thisPin++){pinMode(thisPin,OUTPUT);}}
voidloop(){// iterate over the pins:
for(intthisPin=lowestPin;thisPin<=highestPin;thisPin++){// fade the LED on thisPin from off to brightest:
for(intbrightness=0;brightness<255;brightness++){analogWrite(thisPin,brightness);delay(2);}// fade the LED on thisPin from brightest to off:
for(intbrightness=255;brightness>=0;brightness--){analogWrite(thisPin,brightness);delay(2);}// pause between LEDs:
delay(100);}}