ARDUINO的LED走马灯

本文介绍如何使用Arduino UNO、面包板、LED灯及电阻等材料制作走马灯。通过连接LED灯并利用Arduino编程,实现灯光的依次亮灭效果。适合Arduino初学者实践。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文章是关于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);
 }
 }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值