Skip to content

Instantly share code, notes, and snippets.

@boxalljohn
Last active December 19, 2015 18:18
Show Gist options
  • Select an option

  • Save boxalljohn/5997600 to your computer and use it in GitHub Desktop.

Select an option

Save boxalljohn/5997600 to your computer and use it in GitHub Desktop.
// Example 3.3 – servo examination
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
int del = 100; // delay in micoseconds
void setup()
{
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for (int loopy = 0; loopy<=3; loopy++)
{
for (pos = 180; pos >=0; pos--) // from left to right with Hextronik HXT900
{
myservo.write(pos);
delay(del);
}
delay(1000);
}
for (int loopy = 0; loopy<=3; loopy++)
{
myservo.write(180);
delay (1000);
myservo.write(90);
delay (1000);
myservo.write(0);
delay (3000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment