Fixed a bug above. The idea of good debouncing is to continue the debounce interval until the button has stopped changing state for a specified period. Not to simply wait 200msecs and take the new value at the end of it all. smile

So the code above is happy when the button has a stable state for at least 10msecs (or whatever you change that period to). It need not be a long time.