One button for button push, long press and extra long press

Hi,

Im working on a project where I need one pushbutton to do several tasks.
This is the idea:

  • A short press (press and release):
    Something happens when the button is released

  • Press and hold the button for 1-3 second then release:
    Something happens when the button is releasen within the 1-3 second time.

  • Press and hold the button for 3 seconds:
    Something happens even if the button is not released.

Anyone got a good example for a code that I can work with?

Thanks a lot!

after you develop reliable code to recognize a button press and a button un-press, add code to measure the time between them and then add code to do something base on the duration of the press

gcjr:
after you develop reliable code to recognize a button press and a button un-press, add code to measure the time between them and then add code to do something base on the duration of the press

Another hint: if your button is wired to GND then a button press with be a HIGH to LOW transition and a button release will be a LOW to HIGH transition. Measure the time between those transitions.

As gcjr said, get simple code working that recognizes a button press, then add code to recognize a button release, then add code to time in between...incremental development we call it.

This link has code for 4 different button clicks

Getting a single button to do multiple things can be very confusing for users - how does the user know when s/he has held the button long enough, but not too long?

...R