Here is an example of debouncing a button...
- read the button
- has the button changed states (HIGH to LOW or LOW to HIGH)
- if yes, start a timer...
- ... and store the new button state
- if the timer has exceeded my chosen timeout (50 ms for me)...
- ... check if the button STATE is in the NOT PRESSED state, and the button (not state) is the PRESSED (LOW)
- end of debounce, call a function