evert-arias / EasyButton

Arduino library for debouncing momentary contact switches, detect press, release, long press and sequences with event definitions and callbacks.
https://easybtn.earias.me
MIT License
452 stars 63 forks source link

Does onPressed() have higher priority over onPressedFor()? #25

Closed thkfighter closed 5 years ago

thkfighter commented 5 years ago
//...
void onButton3Pressed(){
//...
}
void button3PressedFiveSeconds(){
//...
}
void button3ISR() {  button3.read(INTERRUPT); }

void setup(){
//...
button3.begin();
button3.onPressedFor(5000, button3PressedFiveSeconds);
button3.onPressed(onButton3Pressed);
//...
if (button3.supportsInterrupt())
  button3.enableInterrupt(button3ISR);
}
void loop(){}

I pressed button3 for more than 5 seconds and then released it, onPressed() responsed instead of onPressedFor().

elC0mpa commented 5 years ago

Hello @thkfighter, are you sure that this es exactly what is happening? I ask you because @evert-arias and i tested this feature before including it to the library and everything was fine. In case this is what is really happening, I could recommend you to increase the debounce time of the button and try it again. Please give us your feedback.

thkfighter commented 5 years ago

Hello @thkfighter, are you sure that this es exactly what is happening? I ask you because @evert-arias and i tested this feature before including it to the library and everything was fine. In case this is what is really happening, I could recommend you to increase the debounce time of the button and try it again. Please give us your feedback.

I'm afraid so. According to your response, I changed the debounce time from default 35ms to 200ms. It did not work either. EasyButton button3(buttonPins[2], 200, true, true); The board is ESP-12S from Ai-Thinker, with three buttons connected on GPIO 4, 5 and 16 respectively.

evert-arias commented 5 years ago

Hi @thkfighter I'm going to run some tests on what you have pointed out and get back to you later. Regards

elC0mpa commented 5 years ago

@thkfighter there is a mistake in your code. If you want to use the onPressedFor functionality through external interrupts, you should call the update method in the loop function as shown here: https://github.com/evert-arias/EasyButton/blob/master/examples/InterruptsOnPressedFor/InterruptsOnPressedFor.ino Please fix this in your code and let us know if everything is working as expected

thkfighter commented 5 years ago

@thkfighter there is a mistake in your code. If you want to use the onPressedFor functionality through external interrupts, you should call the update method in the loop function as shown here: https://github.com/evert-arias/EasyButton/blob/master/examples/InterruptsOnPressedFor/InterruptsOnPressedFor.ino Please fix this in your code and let us know if everything is working as expected

@elC0mpa @evert-arias Thanks a lot. It works.

//...
void loop()
{
  //Main code
  button3.update();
}