Thanks, Peter. Yes, indeed that makes sense. As I'm seeing here, debouncing is hard work and full of surprises! I'm glad I brought it up here, because this is a great technical discussion. I knew I'd be talking to the right people. smile I'll bet it's been discussed here on the BBS previously as well (probably even outside the context of the empeg rotary encoder, too).

The reason I wanted to use a hardware interrupt, instead of just polling the switch each time through the main loop, was because I wanted the button response on this controller to be super snappy. The code spends a lot of time in subroutines, sending data to the LED strands, and doing other things like color blending math, or looping through lists of LEDs. Though I'm doing my best to make sure that the main program loop doesn't get hung up, I was foreseeing a time when maybe the main loop might take a couple hundred milliseconds to come round. In the end, though, I have already given up on the hardware interrupts and gone back to loop polling, because it turns out that I need more total buttons than the Mega2560 will give me hardware interrupts for.

Ultimately, I have switched to using the Button2 library that Elperepat linked. That library is amazing! It handles situations like long presses and hold-downs quite well. Those turned out to be things that I needed. Also, the library can interpret each of its behaviors differently for each button on my device, which also turns out to be something I needed. The library has been frequently updated over the last several years, and its most recent update was less than a month ago, so I feel like I can trust it. Its only drawback is that it depends on the main Loop function instead of button hardware interrupts, but, in my implementation it turned out that I couldn't use hardware interrupts in the end anyway. Thanks for that link, Elperepat!

Mark, thanks so much for the debouncing code. It works well, and I only switched to the library because of my need for the complex special handling routines for long presses and hold downs.

This has been excellent, guys, thanks so much.
_________________________
Tony Fabris