LED跑馬燈-ESP32
LED跑馬燈-ESP32
實驗目的
了解迴圈運用和陣列的宣告 -https://esp32-blairan.blogspot.com/2021/04/esp32_26.html
材料
LED×4
220歐姆電阻×4
杜邦線
ESP32
陣列宣告---
for迴圈-----
const byte led[]={35, 32, 33, 25};
void setup() {
Serial.begin(115200);
for (int i = 0; i <=3; i++)
{
pinMode(led[i], OUTPUT);
}
}
void loop() {
for (int i = 0; i <=3; i++)
{
digitalWrite(led[i], HIGH);
delay(100);
digitalWrite(led[i], LOW);
}
for (int i = 3; i >= 0; i--)
{
digitalWrite(led[i], HIGH);
delay(100);
digitalWrite(led[i], LOW);
}
}
留言
張貼留言