const int touchPin = 2; // the number of the touch pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int touchState = 0; // variable for reading the touch status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the touch pin as an input:
pinMode(touchPin, INPUT);
}
void loop(){
// read the state of the touch value:
touchState = digitalRead(touchPin);
// check if the touch is pressed.
// if it is, the touchState is HIGH:
if (touchState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}