I have another issue now... I am trying to add some error checking to the if statement in the loop() function.
The if statement tests for index to be greater than 4 or inByte to be either a charage return or line feed.
I need to clear inData and break the while loop if index is less than 5, but a charage return/line feed was received.
I have tried several things, but none seem to achieve the intended results. Any ideas?
void loop() {
while (Serial.available() > 0){
inByte = Serial.read (); //read serial input one byte at a time
inData[index] = inByte; //add serial input to array
index++; //increment index (length/bytes of serial data received)
if (index > 4 || inByte == 10 || inByte == 13){ //serial data is 5 bytes longs or received a charage return or line feed
if (index < 5){
//clear inData...
break;
}
inData[index] = '\0'; //Null terminate the string
index = 0; //reset index
unsigned long tmp = atoi(inData);
servo_num = tmp / 1000;
servo_pos = tmp % 1000;
if (servo_pos > 180){
servo_pos = 180;
}
Serial.println(servo_num);
Serial.println(servo_pos);
}
}
}