💽影片名稱:Arduino 11 - FOR 重複與同步🎬集數: 11集
🌐(前往YouTube觀看)-[ https://youtu.be/OPTRnbgLBeE?feature=shared ]
🌐(YouTube播放清單)-[ https://www.youtube.com/playlist?list=PLOrdAySpFIQrg6lLPL5h_AQl4oRo_0ix4 ]
🌐程式創造++ 頻道:[ https://www.youtube.com/@CCplus2561 ]
實作一:重複指令 閃爍5次
|
int LED; //全域 整數變數 命名為LED
void setup() {
pinMode(22,OUTPUT);
pinMode(23,OUTPUT);
}
void loop() {
for( LED=0 ; LED<=5 ; LED++ ){ //重複次數5次
digitalWrite(22,1);
delay(300);
digitalWrite(22,0);
delay(300);
}
digitalWrite(23,1); //觀察是否執行5次
delay(1000);
digitalWrite(23,0);
}
|
實作二:同步迴圈
|
int LED; //全域 整數變數 命名為LED
void setup() {
for( LED=22 ; LED<=37 ; LED++ )pinMode(LED,OUTPUT);
}
void loop() {
for( LED=22 ; LED<=29 ; LED++ ){ //22~29
digitalWrite(LED,1);
}
delay(500);
for( LED=22 ; LED<=29 ; LED++ ){ //22~29
digitalWrite(LED,0);
}
for( LED=30 ; LED<=37 ; LED++ ){ //30~37
digitalWrite(LED,1);
}
delay(500);
for( LED=30 ; LED<=37 ; LED++ ){ //30~37
digitalWrite(LED,0);
}
}
|
請先 登入 以發表留言。