Hello friends, I am trying to use the ESP touch pin for a capacitive button. For single touch, I need to make it to that single touch would register only once. If I touch and hold, it doesn't register multiple single touches. Adding double touch and touch hold would be very helpful. How can I achieve that?
Current basic code from google:
const unsigned long interval=300;
const unsigned long interval_s=600;
unsigned long previoustime=0;
int button=0;
void setup() {
Serial.begin(115200);
}
void loop() {
unsigned long currenttime=millis();
if (touchRead(4) < 30){
if ((currenttime - previoustime >= interval){
Serial.write ("TOUCH");
button=1;
previoustime=currenttime;
}
}
I'm not sure if this approach of using a time interval will work for sensing a hold while registering only one touch for a hold, but any help on this would be greatly appreciated!
Touch is a little bit different from a button because the touchread() function returns a constant stream of values. Based on those values I can tell if the button is being pressed. But I only want to register only one touch if it is someone is holding the touch sensor.