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
447 stars 62 forks source link

To Fix the first time pressed button detection #58

Open i0n- opened 2 years ago

i0n- commented 2 years ago

Code work fine after the first press of the button. When I press by the first time is not detected (failed or missing)... second one and beyond works fine.

With this little change work fine since the beginning.

My current test environment is with the flash button on NodeMCU (ESP8266) board

evert-arias commented 2 years ago

Hi @i0n-, I haven't had time to take a look at this, but I will do it soon.

jPerotto commented 11 months ago

I found the same problem

The solution is:

Add start value of _held_callback_called = false;

void EasyButtonBase::onPressedFor(uint32_t duration, EasyButtonBase::callback_t callback)
{
    _held_threshold = duration;
    _pressed_for_callback = callback;
    _held_callback_called = false;
}