// set pin numbers
const int touchPin = 4;
const int firstLedPin = 18;
const int secondLedPin = 21;
// change with your threshold value
const int threshold = 25;
// variable for storing the touch pin value
int touchValue;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(1000); // give me time to bring up serial monitor (1 second)
pinMode (firstLedPin, OUTPUT);
pinMode (secondLedPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
touchValue = touchRead(touchPin);
Serial.print(touchValue);
// check if the touchValue is below the threshold
// if it is, do blink LED
if (touchValue < threshold){
Serial.println(" - Blink LED");
digitalWrite(firstLedPin, HIGH);
digitalWrite(secondLedPin, LOW);
delay(500);
digitalWrite(firstLedPin, LOW);
digitalWrite(secondLedPin, HIGH);
}
else {
// turn LED off
digitalWrite(firstLedPin, LOW);
digitalWrite(secondLedPin, LOW);
Serial.println(" - LED off");
}
delay(500); // this speeds up the simulation
}