I made the changes and it works great! Thanks for all the help.
I will play around with the tmp math...
//receive 5 numbers via serial. First 2 numbers are the servo number, Second 3 numbers are the servo position
char inData[6]; // Allocate space for incoming serial data (2 digit servo number, 3 digit position)
char inByte; // Incoming serial character
byte index = 0; // Index into array; where to store the character
int8_t servo_num;
uint8_t servo_position;
void setup() {
Serial.begin(9600);
}
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
inData[index] = '\0'; //Null terminate the string
index = 0;
servo_num = getServoNum();
servo_position = getServoPos();
Serial.println(servo_num);
Serial.println(servo_position);
}
}
}
int getServoNum(){
char num[3];
strncpy(num, inData, 2);
num[2] = '\0';
return(atoi(num));
}
int getServoPos(){
uint8_t t_pos = atoi(inData+2);
if (t_pos > 180){
t_pos = 180;
}
return(t_pos);
}