Created
March 8, 2019 23:16
-
-
Save bboyho/781fb2c93336e723f1cf775c7fc16357 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/****************************************************************************** | |
servo-skatch.ino | |
Example sketch for connecting a hobby servo to a sparkfun redboard | |
(https://www.sparkfun.com/products/9065) | |
(https://www.sparkfun.com/products/12757) | |
Byron Jacquot@ SparkFun Electronics | |
May 17, 2016 | |
**SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).** | |
Development environment specifics: | |
Arduino 1.6.5 | |
******************************************************************************/ | |
#include <Servo.h> | |
Servo pan; //along x-axis | |
Servo tilt; //along y-axis | |
Servo claw; //grip | |
int pan_POSITION = 0; // variable to store the servo position | |
int tilt_POSITION = 0; // variable to store the servo position | |
int claw_POSITION = 0; // variable to store the servo position | |
void setup() | |
{ | |
pan.attach(9); // attaches the servo on pin 9 to the servo object | |
tilt.attach(6); // attaches the servo on pin 6 to the servo object | |
claw.attach(3); // attaches the servo on pin 3 to the servo object | |
} | |
void loop() | |
{ | |
for (pan_POSITION = 35; pan_POSITION <= 165; pan_POSITION += 1) { // goes from 0 degrees to 180 degrees | |
// in steps of 1 degree | |
pan.write(pan_POSITION); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
for (pan_POSITION = 165; pan_POSITION >= 35; pan_POSITION -= 1) { // goes from 180 degrees to 0 degrees | |
pan.write(pan_POSITION); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
for (tilt_POSITION = 35; tilt_POSITION <= 165; tilt_POSITION += 1) { // goes from 0 degrees to 180 degrees | |
// in steps of 1 degree | |
tilt.write(tilt_POSITION); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
for (tilt_POSITION = 165; tilt_POSITION >= 35; tilt_POSITION -= 1) { // goes from 180 degrees to 0 degrees | |
tilt.write(tilt_POSITION); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
for (claw_POSITION = 35; claw_POSITION <= 165; claw_POSITION += 1) { // goes from 0 degrees to 180 degrees | |
// in steps of 1 degree | |
claw.write(claw_POSITION); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
for (claw_POSITION = 165; claw_POSITION >= 35; claw_POSITION -= 1) { // goes from 180 degrees to 0 degrees | |
claw.write(claw_POSITION); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment