Skip to content

Short and Long Button Presses Callback #13

Answered by luni64
m-r-m-s asked this question in Q&A
Discussion options

You must be logged in to vote

In this case you can't do it in the callback alone since this is only invoked if the button changed. But it is easy to use a timer for this:

#include "Arduino.h"
#include "EncoderTool.h"

using namespace EncoderTool;
PolledEncoder encoder;

IntervalTimer btnTimer;
bool timerRunning                = false;     // unfortunately the timer has no built in way to find out if it's running
constexpr unsigned longPressTime = 1'000'000; // us

void onLongPress()
{
    btnTimer.end();                                 // trigger only once
    timerRunning = false;

    Serial.println("Long Press\n");
    // do whatever need to be done on a long press here...
}

void onButtonChanged(int32_t state)
{
    

Replies: 8 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@m-r-m-s
Comment options

Comment options

You must be logged in to vote
1 reply
@m-r-m-s
Comment options

Answer selected by m-r-m-s
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@m-r-m-s
Comment options

Comment options

You must be logged in to vote
2 replies
@m-r-m-s
Comment options

@m-r-m-s
Comment options

Comment options

You must be logged in to vote
1 reply
@m-r-m-s
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants