Created
October 25, 2015 23:33
-
-
Save ddworken/c1b9881923bd5d873864 to your computer and use it in GitHub Desktop.
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> | |
const int lowerSensorPin = 2; | |
const int upperSensorPin = 3; | |
const int lowerServoPin = 5; | |
const int upperServoPin = 6; | |
Servo lowerServo; | |
Servo upperServo; | |
int upperPos = 0; | |
int lowerPos = 0; | |
void setup() { | |
lowerServo.attach(lowerServoPin); | |
upperServo.attach(upperServoPin); | |
lowerServo.write(lowerPos); | |
upperServo.write(upperPos); | |
pinMode(lowerSensorPin, INPUT); | |
pinMode(upperSensorPin, INPUT); | |
} | |
void loop() { | |
openClaw(); | |
delay(5); | |
closeClaw(); | |
delay(5); | |
} | |
void openClaw() { | |
lowerServo.write(180); | |
lowerPos = 180; | |
upperServo.write(180); | |
upperPos = 180; | |
} | |
void closeClaw() { | |
while(digitalRead(lowerSensorPin)==LOW){ //while not pressed | |
lowerServo.write(lowerPos--); | |
} | |
while(digitalRead(upperSensorPin)==LOW){ //while not pressed | |
upperServo.write(upperPos--); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment