Example Code for Arduino-Touch
Read touch sensor values.
Hardware Preparation
- 1 x Kitty's Flower
Software Preparation
Wiring Diagram
Touch sensor is connected to pin D6 (refer to Board Overview for pin details).
Other Preparation Work
Open the serial port to view output.
Sample Code
#define TOUCHPIN 6
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(115200);
// make the pushbutton's pin an input:
pinMode(TOUCHPIN, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int touchState = digitalRead(TOUCHPIN);
// print out the state of the button:
Serial.println(touchState);
delay(10); // delay in between reads for stability
}
Result
Touch the stamen, the serial port will output high level; otherwise, it outputs low level.
Additional Information
No additional information.
Was this article helpful?
