int servo1degree, servo2degree;
String str_d;
void Receive_serial_data(){
while (Serial.available()){
char d = (char) Serial.read();
str_d += d;
if(d == '\n') {
Parse_the_data(str_d);
str_d = "";
break;
}
}
}
void Parse_the_data(String &theString)
{
int indexOfA = theString.indexOf("A");
int indexOfB = theString.indexOf("B");
if(indexOfA >-1){
String subStr = theString.substring(indexOfA+1);
servo1degree = subStr.toInt();
Serial.print("Servo1: ");
Serial.println(servo1degree);
}
if(indexOfB >-1){
String subStr = theString.substring(indexOfB+1);
servo2degree = subStr.toInt();
Serial.print("Servo2: ");
Serial.println(servo2degree);
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("START");
}
void loop() {
Receive_serial_data();
}