JC_Button icon indicating copy to clipboard operation
JC_Button copied to clipboard

Not immune to noise :(

Open guillaume-dorczynski opened this issue 3 years ago • 2 comments

Hello Jack

I've been using and recommending this library for years, but recently had a problem with buttons in a project using this library, and after investigating I found that the problem lies in your debounce code.

The problem is that button press/release changes are detected immediately, your code only prevents multiple changes during the debounce time. Therefore, it's not immune to noise!

To be clear, I always thought the button press/release was detected after the debounce time, not before, to wait for the button state to be stabilized.

Here is a Wokwi demo with the debounce time set to one second : https://wokwi.com/projects/353568497230783489

guillaume-dorczynski avatar Jan 11 '23 14:01 guillaume-dorczynski

Greetings,

That's a good catch, thanks. When you discovered the issue, were you using a long debounce time, or was it a noisy environment? Were you able to address the problem, if so, how?

Jack

JChristensen avatar Jan 11 '23 20:01 JChristensen

Hello @JChristensen, @guillaume-dorczynski

Found the same issue due to a noisy switch and when using long(er) debounce times.

Jack, respecting your contributing policy, below are modified .h and .cpp files with changes to the read() function that fixes the issue. Probably not as elegant as your coding style though 😉.

All the best.

Edit: revise the .cpp file.

src.zip

Xylopyrographer avatar Sep 07 '23 21:09 Xylopyrographer