LennartHennigs / Button2

Arduino/ESP button library that provides callback functions to track single, double, triple and long clicks. It also takes care of debouncing.
MIT License
487 stars 81 forks source link

How to handle initial button state? #28

Closed giannoug closed 3 years ago

giannoug commented 3 years ago

Consider the following button: Button2 bigRedButton = Button2(bigRedButtonPin, INPUT_PULLUP, false, false);

For some weird reason, the button is pressed while the Arduino reboots. This doesn't fire any callbacks. I have tried setPressedHandler, setReleasedHandler and setChangedHandler. Since the button is not active low, shouldn't it trigger on boot? It works fine if I release and press it after booting.

LennartHennigs commented 3 years ago

Hey George, I will try to replicate this issue.

LennartHennigs commented 3 years ago

Hey George, I have a hard time duplicating the behavior you describe. But please checkout the latest version via GitHub and give it a try. I updated how I set the Initial values of the state and prev_state vars. Maybe this will solve your issue.