Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Kulangwentao opened this issue Jan 8, 2024 · 4 comments

Comments

@Kulangwentao
Copy link

#include <OneButton.h> //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
Copy link
Author

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

@Kulangwentao
Copy link
Author

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

@JM-FRANCE
Copy link

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

@Kulangwentao
Copy link
Author

Kulangwentao commented Jan 11, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants