arduino非阻塞式延时流水灯用串口来控制的程序
时间: 2023-06-08 12:03:40 浏览: 114
很高兴为您解答问题。以下是您可以使用的Arduino非阻塞式延时流水灯用串口来控制的程序:
```
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int delaytime = 500;
void setup() {
Serial.begin(9600);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
}
void loop(){
if (Serial.available() > 0 ) {
char data = Serial.read();
if (data == '1') delaytime = 1000;
if (data == '2') delaytime = 500;
if (data == '3') delaytime = 250;
}
digitalWrite(LED1, HIGH);
delay(delaytime);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
delay(delaytime);
digitalWrite(LED2, LOW);
digitalWrite(LED3, HIGH);
delay(delaytime);
digitalWrite(LED3, LOW);
digitalWrite(LED4, HIGH);
delay(delaytime);
digitalWrite(LED4, LOW);
}
```
如果您有任何其他问题,欢迎随时向我提出。
阅读全文