I have been using EssyButton for a while and now faced an odd situation which I bring here: I setup OnPressed and OnPressedFor for the same button instance, expecting to trigger either one of them. I mean, if the button pressed shortly then no long event should be triggered - this works well. But when holding down the button and triggering the long press, both events are dispatched, with a leading long press event followed by the short press.
Is it a glitch or am I doing something "off specs". Any clues/tips?
I can not reproduce this behaviour with the following sketch.
#include <EasyButton.h>
EasyButton button(2);
void onPressed() {
Serial.println("Button has been pressed and released.");
}
void onPressedForDuration() {
Serial.println("Button has been pressed for the given duration.");
}
void setup() {
Serial.begin(9600);
button.begin();
button.onPressed(onPressed);
button.onPressedFor(2000, onPressedForDuration);
}
void loop() {
button.read();
}
Tested with a simulator, you can play with it yourself too.
Thanks for your support, @alto777.
Here goes the SCH (pdf attch).
What do you mean with the a7 hint? Analog7 is not being used, though.
Just make sure, can we use Short and Long press evt altogether on the same button?
Is it a possible intended use of the EasyButton lib?
Anyhow, I will benchtest the code as you advised, and try to isolate the behavior context.
My guess is that there is something related to the OLED display lib routines... that is something not included in your test bench. What do you think?
Did you take my link, run the code you (mostly) wrote and observe that yes, shirt and long press events are fine? Go do that now if not. There is nothing like a real test, even using a simulator.
The hint was just to make you realize we need to see a schematic. "a7" is how I end a post, short for @alto777. Sry.
EasyButton is fine. Demonstration of your intended use deployment works well. The schematic looks, at a glance, plausible, but may have an answer.
Personally I would turn up the time it takes for a long press to be the thing. But that is not a problem: one will always get one or the other event, one event per press.
I remain saying the problem is in your real code. Hint. Which is to say, post the code where you think you are getting multiple messages or events for a single click, no matter the duration, of a given button.
Someone else will have to find the problem if three is one in you schematic.
After @alto777 's advices I dblchecked everything under isolate contexts. The only odd thing I've found was that pull-ups were enabled on EasyButton button inits. I am also using pull-ups in my CKT so I disabled the internal pull-ups and somehow the buttons are behaving correctly. I can't tell for sure but that seems to be the "bug".