char inData[5]; // Allocate space for incoming serial data (2 digit servo number, 3 digit position)
Should be 6: 2 + 3 + 1 (Null terminating char needs a spot too)
int getServoPos(){
char pos[4];
strcpy(pos, inData+2);
pos[3] = '\0';
return(atoi(pos));
}
Could be shortened even further:
int getServoPos(){
return(atoi(inData+2));
}
The only reason we copied the server number into it's own array was because it was null-terminated; you don't have that same concern in the server position.
Thinking about it further, you could just do something like this too, and save yourself a couple steps:
unsigned long tmp = atoi(inData);
int servo_num = tmp / 1000;
int servo_pos = tmp % 1000;
So say for example, inData was { '0', '2', '1', '2', '3', '\0' }.
tmp would be 2123.
tmp / 1000 would be 2
tmp % 1000 would be 123