Debouncing button or switch inputs on microcontrollers can be ... you might want to look at this interrupt service routine (ISR) method from [Lee] aka [stockvu]. The strategy with this debounce ...
The Arduino “Bounce” library, which otherwise uses a similar method ... debouncing: a “good enough” RC filter solution, the “guaranteed” hardware solution with a filter and a switch ...