/*
For Loop Iteration
Demonstrates the use of a for() loop.
Lights multiple LEDs in sequence, then in reverse.
The circuit:
- LEDs from pins 2 through 7 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/ForLoopIteration
*/inttimer=100;// The higher the number, the slower the timing.
int型の変数timerを定義し初期化します。
setup()
22
23
24
25
26
27
28
voidsetup(){// use a for loop to initialize each pin as an output:
for(intthisPin=2;thisPin<8;thisPin++){pinMode(thisPin,OUTPUT);}}
voidloop(){// loop from the lowest pin to the highest:
for(intthisPin=2;thisPin<8;thisPin++){// turn the pin on:
digitalWrite(thisPin,HIGH);delay(timer);// turn the pin off:
digitalWrite(thisPin,LOW);}// loop from the highest pin to the lowest:
for(intthisPin=7;thisPin>=2;thisPin--){// turn the pin on:
digitalWrite(thisPin,HIGH);delay(timer);// turn the pin off:
digitalWrite(thisPin,LOW);}}