欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Arduino 制作简易经典流水灯

程序员文章站 2022-07-14 08:23:50
...

今天呢就教大家制作一个简易流水灯,希望大家能够喜欢。
废话不多说,现在我们就开始制作吧!

材料清单:

  1. Arduino 开发板 * 1
  2. Arduino 配线 * 1
  3. LED发光二极管 * 5
  4. 220Ω电阻 * 5
  5. 面包板 * 1
  6. 面包板跳线 若干

接线方法:

Arduino 制作简易经典流水灯

代码如下:

啥都不用说,代码走一波:

void setup() {
  // put your setup code here, to run once:
   pinMode(12,OUTPUT);
   pinMode(11,OUTPUT);
   pinMode(10,OUTPUT);
   pinMode(9,OUTPUT);
   pinMode(8,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(12,HIGH);//LED1亮起
  delay(800);
  digitalWrite(12,LOW);//LED1熄灭
  digitalWrite(11,HIGH);//LED2亮起
  delay(800);
  digitalWrite(11,LOW);//LED2熄灭
  digitalWrite(10,HIGH);//LED3亮起
  delay(800);
  digitalWrite(10,LOW);//LED3熄灭
  digitalWrite(9,HIGH);//LED4亮起
  delay(800);
  digitalWrite(9,LOW);//LED4熄灭
  digitalWrite(8,HIGH);//LED5亮起
  delay(800);
  digitalWrite(8,LOW);//LED5熄灭
  delay(600);
  digitalWrite(8,HIGH);//LED5亮起
  delay(800);
  digitalWrite(8,LOW);//LED5熄灭
  digitalWrite(9,HIGH);//LED4亮起
  delay(800);
  digitalWrite(9,LOW);//LED4熄灭
  digitalWrite(10,HIGH);//LED3亮起
  delay(800);
  digitalWrite(10,LOW);//LED3熄灭
  digitalWrite(11,HIGH);//LED2亮起
  delay(800);
  digitalWrite(11,LOW);//LED2熄灭
  digitalWrite(12,HIGH);//LED1亮起
  delay(800);
  digitalWrite(12,LOW);//LED1熄灭
  delay(1000);
  
  digitalWrite(12,HIGH);//LED1亮起
  delay(800);
  digitalWrite(11,HIGH);//LED2亮起
  delay(800);
  digitalWrite(10,HIGH);//LED3亮起
  delay(800);
  digitalWrite(9,HIGH);//LED4亮起
  delay(800);
  digitalWrite(8,HIGH);//LED5亮起
  delay(800);
  
  digitalWrite(8,LOW);//LED5熄灭
  delay(500);
  digitalWrite(9,LOW);//LED4熄灭
  delay(500);
  digitalWrite(10,LOW);//LED3熄灭
  delay(500);
  digitalWrite(11,LOW);//LED4熄灭
  delay(500);
  digitalWrite(12,LOW);//LED1熄灭
  delay(500);
}

喜欢的话就试试吧!
Arduino 制作简易经典流水灯

相关标签: Arduino arduino