This Example Code Is in The Public Domain Sensor-Servo-Motor
This Example Code Is in The Public Domain Sensor-Servo-Motor
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-touch-
sensor-servo-motor
*/
#include <Servo.h>
void setup() {
Serial.begin(9600); // initialize serial
pinMode(TOUCH_SENSOR_PIN, INPUT); // set arduino pin to input mode
servo.attach(SERVO_PIN); // attaches the servo on pin 9 to the
servo object
servo.write(angle);
currentTouchState = digitalRead(TOUCH_SENSOR_PIN);
}
void loop() {
lastTouchState = currentTouchState; // save the last
state
currentTouchState = digitalRead(TOUCH_SENSOR_PIN); // read new state