Comments (5)
Hey,
I have been using my lib with ESP32s.
What ESP are using?
And did you change the example code (other than the pins)?
Cheers
l.
from button2.
Thanks for the quick response Lennart.
I'm using a MH-ET Live Minikit with ESP-WROOM-32 like this:
In reality, a ILI9341 and stepper motor are connected to other pins, but I don't think they cause the problem.
I used this code to prove the electrical connections are working:
int BTN1 = 21;
int BTN2 = 22;
int BTN3 = 15;
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(115200);
pinMode(BTN1, INPUT_PULLUP);
pinMode(BTN2, INPUT_PULLUP);
pinMode(BTN3, INPUT_PULLUP);
}
// the loop routine runs over and over again forever:
void loop() {
Serial.print(digitalRead(BTN1));
Serial.print(digitalRead(BTN2));
Serial.println(digitalRead(BTN3));
delay(100);
}
This does not provide a response on the handler:
#include "Button2.h"
#define BUTTON_PIN_1 21
#define BUTTON_PIN_2 22
#define BUTTON_PIN_3 15
Button2 button_1, button_2, button_3;
void setup() {
Serial.begin(115200);
delay(50);
Serial.println("\n\nMulti Handler Demo w/ 2 buttons");
button_1.begin(BUTTON_PIN_1);
button_1.setClickHandler(handler);
button_1.setDoubleClickHandler(handler);
button_2.begin(BUTTON_PIN_2);
button_2.setClickHandler(handler);
button_2.setDoubleClickHandler(handler);
button_3.begin(BUTTON_PIN_3);
button_3.setClickHandler(handler);
button_3.setDoubleClickHandler(handler);
}
void loop() {
button_1.loop();
button_2.loop();
button_3.loop();
Serial.print( (button_1.isPressed()) ? "X" : "-");
Serial.print( (button_2.isPressed()) ? "X" : "-");
Serial.print( (button_3.isPressed()) ? "X" : "-");
Serial.println();
delay(200);
}
void handler(Button2& btn) {
switch (btn.getClickType()) {
case SINGLE_CLICK:
Serial.print("single ");
break;
case DOUBLE_CLICK:
Serial.print("double ");
break;
}
Serial.print("click ");
Serial.print("on button #");
Serial.print((btn == button_1) ? " 1 " : " - ");
Serial.print((btn == button_2) ? " 2 " : " - ");
Serial.print((btn == button_3) ? " 3 " : " - ");
Serial.println();
}
Also, if I comment out:
Serial.print( (button_1.isPressed()) ? "X" : "-");
Serial.print( (button_2.isPressed()) ? "X" : "-");
Serial.print( (button_3.isPressed()) ? "X" : "-");
Serial.println();
delay(200);
it is still not working.
I tried fiddling with the constructor and begin() but I did not systematically record what I did.
HenkJan
from button2.
Hey,
I tested your code on a M5Stack Core ESP32.
It worked for me out of the box after I deleted the delay()
and the println's()
in the loop()
:
#include "Button2.h"
#define BUTTON_PIN_1 39
#define BUTTON_PIN_2 38
#define BUTTON_PIN_3 37
Button2 button_1, button_2, button_3;
void setup() {
Serial.begin(9600);
delay(50);
Serial.println("\n\nMulti Handler Demo w/ 2 buttons");
button_1.setClickHandler(handler);
button_1.setDoubleClickHandler(handler);
button_2.setClickHandler(handler);
button_2.setDoubleClickHandler(handler);
button_3.setClickHandler(handler);
button_3.setDoubleClickHandler(handler);
button_1.begin(BUTTON_PIN_1);
button_2.begin(BUTTON_PIN_2);
button_3.begin(BUTTON_PIN_3);
}
void loop() {
button_1.loop();
button_2.loop();
button_3.loop();
}
void handler(Button2& btn) {
switch (btn.getClickType()) {
case SINGLE_CLICK:
Serial.print("single ");
break;
case DOUBLE_CLICK:
Serial.print("double ");
break;
}
Serial.print("click ");
Serial.print("on button #");
Serial.print((btn == button_1) ? " 1 " : " - ");
Serial.print((btn == button_2) ? " 2 " : " - ");
Serial.print((btn == button_3) ? " 3 " : " - ");
Serial.println();
}
(And I used three button pins of the M5Stack in the code above.)
I briefly looked at the pinout of your ESP32: 22 and 21 are also used for I2C on the board.
But you checked the pins, as you wrote, right?
The only problem I could think of, is that you maybe had still a delay()
inside your loop()
.
That would break the button2 loop()
.
Hope this helps...
(I don't have the exact ESP as you do, but I ordered these a few days ago. I can give them a spin when they arrive...)
from button2.
Thanks Lennart, now I understand the loop needs to be called frequently. Presumably my screen update routine takes too long to work well with the library. I still don't get why the out of the box examples did not work though.
from button2.
FYI, you could use an interrupt timer to call the loop. I added an example to the lib.
from button2.
Related Issues (20)
- .pio/libdeps/seeed_xiao_esp32c3/Button2/src/Button2.cpp:186:20: error: 'touchRead' was not declared in this scope HOT 2
- detection of long presses does not work properly inside of an interupt timer HOT 2
- Interrupt wdt timeout on CPU1 HOT 2
- button.isPressed(); seems to stay latched. HOT 1
- Long press is not reported in polling mode HOT 1
- Change std::functional guards from platform-based to language version-based HOT 1
- multiple ESP32CapacitiveTouch.ino HOT 1
- 2.3.0 breaks at least on RP2040 with type errors HOT 3
- 2.3.x breaks default implementation? HOT 4
- Advices for implementing a speed-sensitive button-press control HOT 1
- setStateHandler Functions HOT 1
- Multiplexed buttons support HOT 1
- Use hall sensor instead button HOT 1
- 2.3.x does not compile on Arduino Uno R4 HOT 3
- Watchdog timer triggered on both ESP32 Capacitive Touch examples HOT 1
- virtual button init callback HOT 1
- another i2c PE button question HOT 8
- update constants in examples
- Problem with longpress behavior HOT 3
- [question] Is it compatible with all microcontrollers having an Arduino framework implementation? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from button2.