|
本帖最后由 andywwf 于 2022-1-20 22:53 编辑
目標:
ledPin1 閃2次 -> ledPin2 閃2次 -> ........loop (2 LED 交替閃2次)
問題:
程序寫好, 但就是不懂交替地閃動.
不知道在哪裡出了錯, 請求大佬出頭.
- #define ledPin1 8
- #define ledPin2 9
- #define WW_ON 60
- #define WW_OFF 300
- unsigned long FLASH_START_TIME = 0;
- unsigned long FLASH_START_TIME2 = 300;
- void setup(){
- pinMode(ledPin1,OUTPUT);
- pinMode(ledPin2,OUTPUT);
- }
- void loop(){
- //.......................................................................... LED1
- if(millis()-FLASH_START_TIME<=WW_ON)
- digitalWrite(ledPin1,HIGH);
- else{
- if(millis()-FLASH_START_TIME<=WW_ON*2)
- digitalWrite(ledPin1,LOW);
- else{
- if(millis()-FLASH_START_TIME<=WW_ON*3)
- digitalWrite(ledPin1,HIGH);
- else{
- if (millis()-FLASH_START_TIME<=WW_ON*4)
- digitalWrite(ledPin1,LOW);
- else{
- if(millis()-FLASH_START_TIME<=WW_ON*5)
- digitalWrite(ledPin1,HIGH);
- else{
- if(millis()-FLASH_START_TIME<=(WW_ON*5+WW_OFF))
- digitalWrite(ledPin1, LOW);
- else{
- FLASH_START_TIME=millis();
- }
- }
- }
- }
- }
- }
- //.......................................................................... LED2
- if(millis()-FLASH_START_TIME2<=WW_ON)
- digitalWrite(ledPin2,HIGH);
- else{
- if(millis()-FLASH_START_TIME2<=WW_ON*2)
- digitalWrite(ledPin2,LOW);
- else{
- if(millis()-FLASH_START_TIME2<=WW_ON*3)
- digitalWrite(ledPin2,HIGH);
- else{
- if (millis()-FLASH_START_TIME2<=WW_ON*4)
- digitalWrite(ledPin2,LOW);
- else{
- if(millis()-FLASH_START_TIME2<=WW_ON*5)
- digitalWrite(ledPin2,HIGH);
- else{
- if(millis()-FLASH_START_TIME2<=(WW_ON*5+WW_OFF))
- digitalWrite(ledPin2,LOW);
- else{
- FLASH_START_TIME2=millis();
- }
- }
- }
- }
- }
- }
- }
复制代码
|
|