Created
March 8, 2019 23:50
-
-
Save bboyho/2bb0babe0f0536de255df08187c71b9a 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 = 35; // variable to store the servo position | |
int tilt_POSITION = 35; // variable to store the servo position | |
int claw_POSITION = 35; // variable to store the servo position | |
#define clawButtonPin A1 | |
boolean clawButtonState = HIGH; | |
int potPosition; //this variable will hold a value based on the position of the potentiometer | |
void setup() | |
{ | |
Serial.begin(9600); //start a serial connection with the computer | |
pinMode(clawButtonPin, INPUT_PULLUP); | |
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() | |
{ | |
//read the position of the pot | |
potPosition = analogRead(A0); //set potPosition to a number between 0 and 1023 based on how far the knob is turned | |
Serial.println(potPosition); //print the value of potPosition in the serial monitor on the computer | |
pan_POSITION = map(potPosition, 0, 1023, 35, 165); | |
pan.write(pan_POSITION); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
tilt.write(tilt_POSITION); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
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