Skip to content

Instantly share code, notes, and snippets.

@sarcilav
Created July 27, 2012 02:29
Show Gist options
  • Select an option

  • Save sarcilav/3185870 to your computer and use it in GitHub Desktop.

Select an option

Save sarcilav/3185870 to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int incomingByte = 0; // for incoming serial data
void setup()
{
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(pos);
}
void loop()
{
if(Serial.available() > 0)
{
// read the incoming byte:
incomingByte = Serial.read();
if(incomingByte == 119) // 'w'
pos += 45;
else if(incomingByte == 115) // 's'
pos -= 45;
myservo.write(pos);
delay(15);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment