要如何使用一個按鍵,控制多個led模式

I can only make him flash, but there is no way to control the mode he switches
I don't know how to add music, can someone help me?
This is my code, I am a beginner, please help

int LED1 = 12;
int LED2 = 11;
int LED3 = 10;
int button = 13;
int A = 0;
int B = 0;
int count = 0;
void setup() {
pinMode(13,INPUT);
pinMode(12 , OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
}

void loop() {
A=digitalRead(13);
if(A!=B){
if(A==HIGH){count++;}
}

if(count=1){
digitalWrite(10, 1);

digitalWrite(12,1);  

delay(100);
digitalWrite(12,0);
delay(5000);

digitalWrite(11, 1);
delay(100);
digitalWrite(11, 0);
delay(1000);
}
if(count=2){
digitalWrite(10, 1);

digitalWrite(12,1);  

delay(100);
digitalWrite(12,0);
delay(5000);

digitalWrite(11, 1);
delay(100);
digitalWrite(11, 0);
delay(100);

}
if(count=3){

digitalWrite(10, 0); 

digitalWrite(12, 0);  
                     
digitalWrite(11, 0);   

count=0;

}
}

Please do not create a post in 'Uncategorized'.
Since - I think - none of us knows Chinese, it would make more sense to formulate your question in English.

這個迴圈太短了,不能多次按下按鈕......所以計數=2和計數=3永遠不會發生

  if (A != B) {
    if (A == HIGH) {
      count++;
    }
  }

按兩下此代碼類比。

  1. 使 LED 工作。
  2. 使按鈕工作
  3. 讓音樂發揮作用
  4. 使按鈕播放音樂
  5. 使按鈕更改LED和音樂。

使用"delay(x)"將使你的代碼不適用於其他事件(音樂、按鈕)。這稱為"阻止"。

閱讀關於 "millis()" 以及如何使事件在確切的時間發生。;以及如何使事件在確切的時間發生。

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.