Skip to content

Instantly share code, notes, and snippets.

@dustynrobots
Created August 31, 2012 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustynrobots/3548699 to your computer and use it in GitHub Desktop.
Save dustynrobots/3548699 to your computer and use it in GitHub Desktop.
This is the Arduino code needed to allow the Processing sketch to move the robot arm
// by David Cummings 8/30/2012
#include <Servo.h>
Servo Elbow; // create servo object to control a servo
Servo Shoulder;
int e_pos = 90; // variable to store the servo position
int s_pos = 90;
char read_char;
void setup()
{
Serial.begin(9600);
Elbow.attach(3); // attaches the servo on pin indicated to the servo object
Shoulder.attach(5);
Shoulder.write(90); // some default start-up values, make these match your robot's settings
Elbow.write(30);
}
void loop()
{
if(Serial.available()>1){
read_char = Serial.read();
if(read_char == 's'){
s_pos = Serial.read();
}
else if(read_char == 'e'){
e_pos = Serial.read();
}
else{
}
}
Shoulder.write(s_pos);
Elbow.write(e_pos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment