// ESP32 - Control LED with two touch pins
// One touch = LED ON, Another touch = LED OFF
const int ledPin = 2; // Onboard LED (GPIO2)
// Choose touch pins
const int touchOn = T0; // GPIO4 → Touch pin for ON
const int touchOff = T3; // GPIO15 → Touch pin for OFF
int threshold = 40; // Adjust experimentally
int touchValueOn, touchValueOff;
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // LED initially OFF
}
void loop() {
// Read touch values
touchValueOn = touchRead(touchOn);
touchValueOff = touchRead(touchOff);
Serial.print("ON pin: ");
Serial.print(touchValueOn);
Serial.print(" | OFF pin: ");
Serial.println(touchValueOff);
// If ON touch detected
if (touchValueOn < threshold) {
digitalWrite(ledPin, HIGH);
}
// If OFF touch detected
if (touchValueOff < threshold) {
digitalWrite(ledPin, LOW);
}
delay(100);
}