Touch interrupt is not detaching.
Code: Select all
int threshold = 20;
bool touch1detected = false;
void gotTouch1() {
touch1detected = true;
}
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("ESP32 Touch Interrupt Test");
touchAttachInterrupt(T0, gotTouch1, threshold);
delay(1000);
detachInterrupt(T0);
delay(1000);
}
void loop() {
if (touch1detected) {
detachInterrupt(T0);
touch1detected = false;
Serial.println("Touch 1 detected");
Serial.println(touchRead(T0));
}
}
06:47:12.228 -> Touch 1 detected
06:47:12.228 -> 15
06:47:12.275 -> Touch 1 detected
06:47:12.275 -> 0
06:47:12.275 -> Touch 1 detected
06:47:12.275 -> 9
06:47:12.322 -> Touch 1 detected
06:47:12.322 -> 8
06:47:12.322 -> Touch 1 detected
06:47:12.322 -> 6
06:47:12.368 -> Touch 1 detected
06:47:12.368 -> 5
06:47:12.368 -> Touch 1 detected
06:47:12.368 -> 6
06:47:12.415 -> Touch 1 detected
06:47:12.415 -> 5
How to solve the problem?
Thanks