Skip to content

Instantly share code, notes, and snippets.

@akbsteam
Created March 3, 2013 16:24
Show Gist options
  • Select an option

  • Save akbsteam/5076754 to your computer and use it in GitHub Desktop.

Select an option

Save akbsteam/5076754 to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo twistServo; // Define left servo
Servo nodServo; // Define right servo
int twistPos = 0;
int nodPos = 0;
int maxNod = 180;
int minNod = 90;
int minTwist = 60;
int maxTwist = 120;
void setup() {
twistServo.attach(10); // Set left servo to digital pin 10
nodServo.attach(9); // Set right servo to digital pin 9
}
void loop() {
for(nodPos = minNod; nodPos < maxNod; nodPos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
nodServo.write(nodPos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(twistPos = minTwist; twistPos < maxTwist; twistPos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
twistServo.write(twistPos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(twistPos = maxTwist; twistPos>=minTwist; twistPos-=1) // goes from 180 degrees to 0 degrees
{
twistServo.write(twistPos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(nodPos = maxNod; nodPos>=minNod; nodPos-=1) // goes from 180 degrees to 0 degrees
{
nodServo.write(nodPos); // 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