I recently have been working on a little project. Unfortunately, I've ran into a bit of a road block with controlling servos using serial commands. The servos do appear to move when i put in any character into serial, but only a little. When i type in say, 90 characters of random gibberish, both servos connected to my arduino move several degrees. Here's my code:
#include <Servo.h>
Servo ULF; // Upper left front servo
Servo LLF; // Lower left front servo
byte index = 0;
int commandnum=1;
int steps = 0; // position of LLF servo
int partnum = 0; // unused for now
String command = ""; // the command we're building
void setup()
{
LLF.attach(0);
ULF.attach(1);
Serial.begin(9600);
}
void loop()
{
while(Serial.available() > 0) { // while there are more than zero bytes to read
char in = Serial.read();
if(in=='!') {
//! is escape character
commandnum++;
partnum = 0;
Serial.println("New Command. Command #: "+commandnum);
break;
}
command+=in;
if(in == ' ') {
partnum++;
//if we have a space, there's a new section to the command
}
if(command == "LLF") {
Serial.read(); //skip a space
Serial.println("Lower Left Foot Selected.");
int angle = Serial.parseInt(); // find the angle we want
Serial.println("ANGLE: "+String(angle));
for(int pos = 0; pos < angle; pos++) // for loop through positions to reach goal
{
LLF.write(pos); // write servo position
delay(15);
}
for(int pos = angle; pos > 0; pos--) // for loop through positions to reach goal
{
LLF.write(pos); // write servo position
delay(15);
}
}
}
}
Any help would be much appreciated.
EDIT: Another note, nothing is printed in the serial monitor.
Also, these are micro towerpro rc servos.