DebounceInput icon indicating copy to clipboard operation
DebounceInput copied to clipboard

Combine with interrupts?

Open wimpie3 opened this issue 10 years ago • 1 comments

Paul, would it be possible to combine DebounceInput with an interrupt? I've tried that but it's not working.

The problem is: if you have a fairly large loop, DebounceInput cannot be fired fast enough. Since an interrupt, well, interrupts the loop, might this be the way to go for long running loops?

wimpie3 avatar Sep 25 '15 15:09 wimpie3

I can't see any reason why this wouldn't work, but I don't have a lot of experience with interrupts. The outer wrapper class - DebounceInput - uses digitalRead() and millis(). I don't know if they work ok inside an ISR. Maybe you need to be using the lower-level "filter" classes. Maybe the issue is that your ISR only fires on "button down" events, so DebounceInput only ever sees the button in an "on" state.

Have you managed to make a simple sketch to turn an LED on and off? Do the example sketches work for you? That would be the first thing. If they aren't going, then the problem isn't this big loop of yours, it's an issue with installing the library on your environment.

The real solution, of course, is to redo your sketch so that the loop runs fast, to make your sketch a state machine rather than a script. But in the meantime, it all depends on what "combine" means and "isn't working" means. I mean - does your sketch work with an ISR that isn't trying to debounce input? Apart from the occasional button bounce, does you sketch do what you think it should do if you just use the raw digital input in your ISR?

PaulMurrayCbr avatar Sep 28 '15 16:09 PaulMurrayCbr