Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 4 months ago.
Short press and long press on one button
I have two actions defined on one button, one action for "Pressed" and one action for "PressedHeld", this works. But when I do a long press the short press action always triggers first, then the long-press action triggers. I would like to get the long-press action only when a button is long-pressed, is this possible with this library ? Thanks !
Question relating to:
1 Answer
9 years, 4 months ago.
Use attach_asserted_held for the long press and attach_deasserted for the short press.
You will only get the short press notification when they let go of the button rather than almost as soon as it's pressed but you can't know it's a short press until then anyway.
Hi Andy
I have a similar problem.
I have set up a button "sw2" the following way:
sw2.attach_deasserted( &sw2Frequency );
sw2.attach_asserted_held( &sw2TransceiveMode_held );
sw2.setSamplesTillAssert( 1 );
sw2.setSamplesTillHeld( 100 ); Held press for 20*100ms = 2 seconds
sw2.setAssertValue( 0 );
sw2.setSampleFrequency( 20000 );
What I want is:
- when sw2 is pushed and quickly released, sw2Frequency function is called.
- when sw2 is pushed and held for 2 seconds, sw2TransceiveMode_held function is called.
What I get is:
- when sw2 is pushed and quickly released, sw2Frequency function is called. (as I expect)
- when sw2 is pushed and held for 2 seconds, sw2TransceiveMode_held function is called. As I expect, EXCEPT when the button is released again, sw2Frequency function gets called.
How can I avoid calling sw2Frequency when releasing after a held press?
Thank you!
posted by 20 Sep 2015