Octal Button Debouncer
Dan E
Posts: 61
Hi,
I was looking for a debounce object in the object exchange, and I saw the Octal button debouncer. I assume from reading through the D8C_BUTEngine that it can handle up to 8 debounce buttons.
I am looking to have six different push buttons in my project, and I wanted each of them when pressed to interrupt the main program to perform their respective function.
Can this program able to do these tasks at any point in time during a main program when pressed?
Thanks,
Dan
I was looking for a debounce object in the object exchange, and I saw the Octal button debouncer. I assume from reading through the D8C_BUTEngine that it can handle up to 8 debounce buttons.
I am looking to have six different push buttons in my project, and I wanted each of them when pressed to interrupt the main program to perform their respective function.
Can this program able to do these tasks at any point in time during a main program when pressed?
Thanks,
Dan
Comments
Thanks,
Dan
Here is what I actually tried:
And here is the full code, I added sound to test if the buttons were working or not, using the setup I already had.
debounce test - Archive [Date 2011.01.25 Time 11.20].zip
Thanks,
Dan
Simpler is often better.
I always love your posts because they are simple, straight forward, clever, and exactly what's needed. This one is no exception, although it leaves me wondering what happens if debounce returns with more than one bit high. Is that even possible if someone were to hold 2 buttons for more than 50ms?
Thanks,
Peter
Thanks for the kind words. You'll note that in Main a case structure is used; you could in fact use this to detect multiple inputs (I used binary to make this easier to visualize). If the return value falls through the case structure without a match then nothing happens. If you want a default action for no match you can use the other option with case.
There is an advantage to returning multiple pins: you could use one as a "shift" key and get 10 sections (five un-shifted, five shifted) from your six inputs.
Keep in mind that the debounce method works by checking which pin(s) stayed pressed during the debounce period, that is, they didn't bounce. In your practical application you may want to allow the audio to finish before rescanning or, at the very least, force a release of all buttons (return of %000000) before going back to the top of your scan loop.
Thanks for answering my question. I'd forgotten that case has a default case. I like your idea if a shift button and with the binary representation for the individual cases, that's a very easy thing to visualize (and code). I'll have to remember this post next time I need button debounce.
Regards,
Peter