Created
August 29, 2019 06:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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