Skip to content

Instantly share code, notes, and snippets.

@toddaeverett
Last active November 5, 2015 05:33
Show Gist options
  • Save toddaeverett/558b35e2fe1d7b538ffa to your computer and use it in GitHub Desktop.
Save toddaeverett/558b35e2fe1d7b538ffa to your computer and use it in GitHub Desktop.
/*
Based off of "sweep" by Barragan:
https://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 90; // variable to store the servo position
int const potPin = A0;
int potVal;
int tempo;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
potVal = analogRead(potPin);
for (pos = 75; pos <= 115; pos += 10) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(potVal);
for (pos = 115; pos >= 75; pos -= 10) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(potVal);
// myservo.write(pos); // center servo for arm attachment
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment