Hey all!
I trying to control 5 or 6 servos from TD.
Thats Arduino scetch I uploaded currently:
[code]#include <Servo.h>
Servo mservo1;
Servo mservo2;
Servo mservo3;
Servo mservo4;
Servo mservo5;
int pos = 0;
String readString, servo1, servo2, servo3, servo4, servo5;
void setup() {
Serial.begin(9600);
mservo1.attach(9);
mservo2.attach(10);
mservo3.attach(11);
mservo4.attach(3);
mservo5.attach(5);
}
void loop() {
while ( Serial.available() ){
delay(3);
if(Serial.available()>0){
char c = Serial.read();
if(c=='!'){
break;
}
readString +=c;
}
}
if(readString.length() >0 ){
Serial.println(readString);
servo1 = readString.substring(0,3);
servo2 = readString.substring(3,6);
servo3 = readString.substring(6,9);
servo4 = readString.substring(9,12);
servo5 = readString.substring(12,15);
int n1 = servo1.toInt();
int n2 = servo2.toInt();
int n3 = servo3.toInt();
int n4 = servo4.toInt();
int n5 = servo5.toInt();
mservo1.write(n1);
mservo2.write(n2);
mservo3.write(n3);
mservo4.write(n4);
mservo5.write(n5);
readString="";
}
}[/code]
Actually it works BUT, really often as I see in debug string I recieving in Serial DAT,
it gets shorter or longer string.
Example in screenshot.
ANy Ideas how to solve it?