Generic debounce logic (or, how do I pass variables by reference?)

Arrays and functions are passed by reference.

If you search the forum for “debounce” there’s a few different examples, but I think this one is probably close to what you’re looking for: