const byte LED1 = 8; //宣告變數給LED1~5
const byte LED5 = 12;
int i; //宣告一個整數i,以做為計數用
int j; //宣告另一個整數j,做為計數用
int dt = 1000; //宣告dt為1000,做為delay time用
void setup() {
// put your setup code here, to run once:
for (i = LED1; i <= LED5; i++) { //使用for迴圈指令依次將LED1~5設定為輸出
pinMode(i, OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
for (i = LED1; i < LED5; i++) { //用for迴圈指令將LED1~5依次亮暗
digitalWrite(i, HIGH);
delay(dt);
digitalWrite(i, LOW);
}
for (j = LED5; j > LED1; j--) { //用for迴圈指令將LED5亮滅回到LED1
digitalWrite(j, HIGH);
delay(dt);
digitalWrite(j, LOW);
}
}