After many¬†frustrating¬†hours, seeing as I have never liked working with interrupts that much, I finally have an addition to my digital library which can handle buttons, and is nicely scalable. Plus it plays nice with all other bits of code that I’ll eventually be running on BOB.

To solve the problem of debouncing the button inside of an interrupt, and doing it fairly fast and efficiently, I finally settled with sticking a small counter inside of Timer0 over flow interrupt. Every time the timer overflows, it triggers the interrupt, which in turn checks the state of all the button pins. If a button is pressed, it’ll start a counter, every time the button bounces the counter resets, until it eventually settles enough to increase the counter without reseting it, marking it as being pressed, at which point a function in the debouncing code (that is outside of the interrupt) will reset the counter again, and change the state indicator bit for the rest of the program to use, in this case a third function with takes care of handling button functions.

The nice thing about this is that it’s scalable, and yet doesn’t bog down the core too much, plus it works great, heres the digital.c library: