How to detect button Long press and short press,where buttons acts as gpio interrupts
I have tried something like below in my interrupt function but i was unable to detect long press ,every time it was detecting short press.
static timestamp_pressed=-1;
if (timestamp_pressed == -1)
{
user just pressed the button
timestamp_pressed = HAL_GetTick(); // milliseconds since startup
}
if (HAL_GetTick() - timestamp_pressed > 3000)
{
// 3000 milliseconds = 3 seconds are over
state_Long=1;
timestamp_pressed = -1;
}
else
{
state_short=1;
timestamp_pressed=-1;
}
