Skip to content

Instantly share code, notes, and snippets.

@suadanwar
Created August 29, 2019 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suadanwar/3b84699416cdeaa31e310b3647146460 to your computer and use it in GitHub Desktop.
Save suadanwar/3b84699416cdeaa31e310b3647146460 to your computer and use it in GitHub Desktop.
This sample code is for Chocolate Box with Touch Sensor and Arduino's tutorial.
#include <Servo.h>
Servo myservo1;
Servo myservo2;
int touchSensorPin = 2;
int touchSensorState = 0;
void setup() {
myservo1.attach(9);
myservo2.attach(10);
pinMode(touchSensorPin, INPUT);
}
void loop() {
if (digitalRead(touchSensorPin) == 1) {
myservo1.write(180);
delay(15);
while (1) {
myservo2.write(0);
delay(1000);
myservo2.write(180);
delay(1000);
if (digitalRead(touchSensorPin) == 1) {
myservo1.write(0);
delay(1000);
break;
}
}
}
else {
myservo1.write(0);
delay(15);
myservo2.write(180);
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment