Created
August 31, 2012 03:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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