Let's help make the code clearer by posting it correctly so that it is easier to read
int threshold = 60;
bool touchdetected5 = false;
bool touchdetected4 = false;
const byte led_gpio1 = 32;
const byte led_gpio2 = 33;
const byte led_gpio3 = 36;
int value = 0;
volatile unsigned long sinceLastTouch5 = 0;
volatile unsigned long sinceLastTouch4 = 0;
void gotTouch5()
{
if (millis() - sinceLastTouch5 < 500) return;
sinceLastTouch5 = millis();
touchdetected5 = true;
}
void gotTouch4()
{
if (millis() - sinceLastTouch4 < 500) return;
sinceLastTouch4 = millis();
touchdetected4 = true;
}
void setup()
{
Serial.begin(115200);
pinMode(led_gpio1, OUTPUT);
pinMode(led_gpio2, OUTPUT);
pinMode(led_gpio3, OUTPUT);
delay(1000); // give me time to bring up serial monitor
printf("\n ESP32 Touch Interrupt Test\n");
touchAttachInterrupt(T5, gotTouch5, threshold); // T0 = GPIO 4
touchAttachInterrupt(T4, gotTouch4, threshold); // T3 = GPIO 15
}
void loop()
{
if (touchdetected4 && touchdetected5)
{
touchdetected5 = false;
touchdetected4 = false;
digitalWrite(led_gpio3, HIGH);
delay(150);
digitalWrite(led_gpio3, LOW);
delay(150);
Serial.print("Both Teouched - Value: ");
Serial.println(value = value - 1);
}
if (touchdetected5)
{
touchdetected5 = false;
digitalWrite(led_gpio1, HIGH);
delay(150);
digitalWrite(led_gpio1, LOW);
delay(150);
Serial.print("Touch 5 detected - Value: ");
Serial.println(value = value - 1);
}
if (touchdetected4)
{
touchdetected4 = false;
digitalWrite(led_gpio2, HIGH);
delay(150);
digitalWrite(led_gpio2, LOW);
delay(150);
Serial.print("Touch 4 detected - Value: ");
Serial.println(value = value + 1);
}
}