Hello
I want to get push switch status from an analog read. I tried many library, but did not succeed to get data for a long press,
At the moment, I'm able to read the analog value for 4 switchs, and get witch key as been pressed. Now,
I want to properly debounce it, get if the switch is a click or a long press.
I tried, these library: with no success: Multibutton, Multibuttons, ButtonFever. end few others
Any input appreciated
Martin
Have you got multiple buttons with different associated resistors attached to the same analogue pin ?
Hello UKHeliBob
Yes, I got the resistor voltage divider. I read the proper value for each key on one analog pin.. My problem is with debouncing the read and get if it is a click or a long press.
Martin
Hello arjfca
We need some additional information.
Post your sketch, well formated, with well-tempered comments and in so called code tags "< code >" and a detailed circuit diagram to see how we can help.
Have a nice day and enjoy coding in C++.
A part of the problem is resolved. The read is debouced using a timer. The proper key pressed is decoded.
Now, where to add a timer for a long press after debouncing?
#include <Every.h>
Every debounce(50,true); //debounce timer True on first instance
Every::Timer LongPress(1000); // Valid if a switch is pressed for 1 second
void ReadSwitchButton(){ // Read button switch
//up button 1024
//down 293
//Left 82
//Right 30
//No_SW 12
unsigned int value = analogRead(ANALOG_PIN);
if (value <=NO_SW) {
SW=0;
return;
}
if ( debounce() ){
if ((value >= (SW1 - SW1_MIN)) && (SW1 <= (SW1 + SW1_SUP))){
SW =1;
}
else if ((value >= (SW2 - SW2_MIN)) && (SW2 <= (SW2 + SW2_SUP))){
SW =2;
}
else if ((value >= (SW3 - SW3_MIN)) && (SW3 <= (SW3 + SW3_SUP))){
SW =3;
}
else if ((value >= (SW4 - SW4_MIN)) && (SW4 <= (SW4 + SW4_SUP))){
SW =4;
}
}
}