I am having some trouble controlling 2 servos with my arduino motor shield. I am getting some unexpected errors in my code. I am trying to control the servos using the serial monitor window. I got my code from the video Two servo motors control through Arduino serial - YouTube
I understand the ServoTimer.h command does not work, and i have tried changing it to Servo.h but that have not worked. Can anyone please help me figure this out or provide another way (code) of controlling 2 servos with the motor shield. The code it below.
Thanks
/* two servo controller
serial input format
protocol;motor_number=angle
ex: 1=180@ or 2=56@
*/
#include <ServoTimer1.h>
ServoTimer1 servo1;
ServoTimer1 servo2;
int inByte = 0;
char buf[256];
char stopByte='0';
void setup()
{
delay(500);
Serial.begin(9600);
servo1.attach(10);
servo2.attach(9);
Serial.println("I am ready")
}
void loop()
{
int i=0
while(true){
if (Serial.available() > 0) {
inByte = Serial.read();
if(inByte==stopByte){
buf[i]='\0';
break;
}
buf[i]=inByte
i++
Serial.print("I received: ");
Serial.println(inByte);
}
}
Serial.print("I received string: ");
Serial.println(buf);
char motor = buf[0];
int k = 2
while(buf[k] != '\0'){
buf[k-2] = buf[k];
k++;
}
buf[k-2] = '\0';
int angle=atoi(buf);
if(motor == '1'){
Serial.print("Motor is 1, and angle is: ");
Serial.println(angle);
servo1.write(angle);
}
else if(motor == '2'){
Serial.print("Motor is 2, and angle is: ");
Serial.println(angle);
servo2.write(angle);
}
}
Moderator edit: I took the italics out of your code using CODE TAGS. I hope you don't mind.
