One button, two behaviours, non-blocking code

you only execute the timer when there is a button state change.

  • check for a state change
  • if pressed, capture a timestamp
  • if release, report short press
  • if the button is being pressed check if timeout exceeded and report long press