mathertel / OneButton

An Arduino library for using a single button for multiple purpose input.
http://www.mathertel.de/Arduino/OneButtonLibrary.aspx
Other
920 stars 230 forks source link

TwoButtons , only the first button work, the second button can not work。两个按键错误。 #137

Open Kulangwentao opened 6 months ago

Kulangwentao commented 6 months ago

include //OneButton库,按钮按下与长按操作

OneButton button1(15,false,false); //左侧按钮,D8-GPIO15,靠近芯片的插座 OneButton button2(4,false,false); //右侧按钮,D2-GPIO4,远离芯片的插座

void button1Click(){ //单击button1时运行 Serial.print("button1Click"); }

void button2Click(){ //单击button2时运行 Serial.print("button2Click"); }

void setup(){ Serial.begin(9600); while(!Serial); Serial.println("Ready");

button1.reset(); button1.attachClick(button1Click);

button2.reset(); button2.attachClick(button2Click);

}

void loop() { button2.tick(); button1.tick(); }

According to the above code, only button1 can work. If the order is reversed below, only button2 can work.

OneButton button2(4,false,false); //右侧按钮,D2-GPIO4,远离芯片的插座 OneButton button1(15,false,false); //左侧按钮,D8-GPIO15,靠近芯片的插座

用OneButton库定义了两个按钮,但是只有前面一个被定义的可以工作,后一个不工作,调换顺序之后还是前面一个可以工作,求助,为什么?哪里错了? /

Kulangwentao commented 6 months ago

我发现了问题,因为我在loop里调用了fastled库中的fill_rainbow((leds), 64, 0, 4); 然后我尝试了如果把led灯数量减少到4个那按键就正常了,不知道是不是因为led控制这边速度太慢了?

Kulangwentao commented 6 months ago

问题已经解决了,是因为在调用fastled的时候数量搞错了导致的。

JM-FRANCE commented 6 months ago

so problem solved, it was a bug in your code. this could be closed, right?

Kulangwentao commented 6 months ago

Yes, thank you.

At 2024-01-10 21:01:37, "JM" @.***> wrote:

so problem solved, it was a bug in your code. this could be closed, right?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>