void setup() {
Serial.begin(9600);
String input = "s421";
char pinArray[2];
input.substring(1,3).toCharArray(pinArray, 3);
char stateArray[1];
input.substring(3,4).toCharArray(stateArray, 2);
int x = atoi(pinArray);
int y = atoi(stateArray);
Serial.println(x);
Serial.println(y);
}
When I try to print the values of both charArrays together, one of the values will be wrong. However, when I remove either one of the .toCharArray conversion statements, the other value will start showing correctly. The correct values for x should be 42 and y is 1. Can someone please tell me what is going on? Thank you.