请编写程序实现以下功能,在一个程序中完成以下功能中的三种花色,亮灯跑马灯,暗灯跑马灯,亮灯乒乓灯,暗灯跑马灯(包括上移下移),一隔一点亮,二隔二点亮,四个灯交替点亮。
时间: 2023-10-09 07:17:22 浏览: 71
电信设备-双向通讯的无线暗灯系统.zip
以下是使用 Arduino 编写的程序,可以实现上述功能:
```c++
const int led1 = 2; // 三种花色
const int led2 = 3;
const int led3 = 4;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop() {
// 亮灯跑马灯
digitalWrite(led1, HIGH);
delay(100);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led3, LOW);
// 暗灯跑马灯
digitalWrite(led1, LOW);
delay(100);
digitalWrite(led2, LOW);
digitalWrite(led1, HIGH);
delay(100);
digitalWrite(led3, LOW);
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led1, LOW);
digitalWrite(led3, HIGH);
delay(100);
// 亮灯乒乓灯
digitalWrite(led1, HIGH);
delay(200);
digitalWrite(led2, HIGH);
delay(200);
digitalWrite(led1, LOW);
delay(200);
digitalWrite(led2, LOW);
delay(200);
// 暗灯跑马灯(上移下移)
digitalWrite(led1, LOW);
delay(100);
digitalWrite(led3, LOW);
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
delay(100);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(100);
// 一隔一点亮
digitalWrite(led1, HIGH);
delay(100);
digitalWrite(led1, LOW);
delay(100);
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay(100);
digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led3, LOW);
delay(100);
// 二隔二点亮
digitalWrite(led1, HIGH);
delay(200);
digitalWrite(led1, LOW);
delay(200);
digitalWrite(led2, HIGH);
delay(200);
digitalWrite(led2, LOW);
delay(200);
digitalWrite(led3, HIGH);
delay(200);
digitalWrite(led3, LOW);
delay(200);
// 四个灯交替点亮
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(100);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(100);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(100);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
delay(100);
}
```
阅读全文