Does anyone have a code that would allow me to manually input the position of two servos using the serial monitor function? The code i an currently using is giving me:
servos2.cpp: In function 'void loop()':
servos2:27: error: expected ',' or ';' before 'while'
servos2:68: error: expected `}' at end of input
Can someone fix my code or provide me with one that works. Thanks. Here is what I have so far:
/* two servo controller
serial input format
protocol;motor_number=angle
ex: 1=180@ or 2=56@
*/
#include <Servo.h>
Servo servo1;
Servo 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);
}
}