I wondering what is the best way to manage short press vs long press on a button.
I'm using a single button for two function: reset the values with a short press and reset/changing mode with a long press.
Here is the code I've done by myself:
//RESET BUTTON
if (bt_reset.isPressed()) //test button
{
delay(200); //no bounce delay
if (!bt_reset.stateChanged()) //if button still pressed
{
delay(300); //waiting a little more for long press
if (!bt_reset.stateChanged()) //if button still pressed
{
is_rotor=!is_rotor; //changing mode
EEPROM.write(1, is_rotor); //Eeprom save
}
}
for (int i = 0; i < 3 ; i++) //reset values
{
max_pressure_PSI[i] = 0; // set all measures to 0
max_pressure_bars[i] = 0; // set all measures to 0
rpm[i] = 0; //set all rpm to 0
}
max_pressure_OK = false; //reset bolean
rotor_face = 0; //reset rotor face
}
I have a small issue with this: when still pressing the button continuously the boolean is_rotor is changing every 0.5 seconds.
Is it a good way to check short vs long?
How to avoid the value for changing every 0.5 seconds ?