本文章是关于ARDUINO中刚入门的LED灯的走马灯
需要的材料
Arduino 编程软件
Arduino UNO卡
面包板
5 x 连接线
4 x LED灯
4 x 220 - 1000欧的电阻
实验内容
准备齐全后,我们就可以开始实验了!
具体连接如图所示
源码
int FirstLED = 3; // 第一个输出口
int LastLED = 6; // 最后一个输出口
int timer = 300; // 每个灯点亮的时间
void setup()
// use a for loop to initialize each pin as an output:
for (int thisPin = FirstLED; thisPin <= LastLED; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// 这里从9号灯到13号灯
for (int thisPin = FirstLED; thisPin <= LastLED; thisPin++) {
// 点亮
digitalWrite(thisPin, HIGH);
delay(timer);
// 熄灭
digitalWrite(thisPin, LOW);
}
for(int thisPin=LastLED;thisPin>=FirstLED;thisPin--){
digitalWrite(thisPin,HIGH);
delay(100);
digitalWrite(thisPin,LOW);
}
}