int LEDState = 0;
int touchInput = 2;
int inputState;
int lastInputState = 1;
int LEDPin = 13; // Define the LED pin
void setup() {
Serial.begin(9600);
pinMode(LEDPin, OUTPUT);
pinMode(touchInput, INPUT);
}
void loop() {
inputState = digitalRead(touchInput);
if (lastInputState == 0 && inputState == 1) {
if (LEDState == 0) {
digitalWrite(LEDPin, HIGH);
LEDState = 1;
Serial.println("Touch detected. LED turned ON.");
} else {
digitalWrite(LEDPin, LOW);
LEDState = 0;
Serial.println("Touch detected. LED turned OFF.");
}
}
lastInputState = inputState;
delay(100); // Adjust the delay as needed
}