I hope I posted this item all right, I got the advise to read "how to post a question" . I use the Serial.read statement to read in a string. When a comma is read, the program should clear the input string.
I store the input in an array STRING []. When I print the strings, the first one dispays OK, the others are preceded by an "open square", see attachment.
Question: What is happening and how can I avoid this. This makes it impossible to check the strings on further development.
Below my sourcecode:
int stringTel = 0;
String rx_str;
char rx_byte;
String rx_str_old = "";
String inputStrings[5]= {"een","twee","drie","vier"};
void setup(){
Serial.begin(115200);
Serial.println("readInput_20191003");
Serial.println("printen intitwaarde");
for (int localTel2 = 0; localTel2 < 3;localTel2++){
Serial.println(inputStrings[localTel2]);
}
}
void loop(){
input();
if (inputStrings[1] == "vijf"){
Serial.println("goed gezien");
Serial.println(inputStrings[1]);
}
/*
else{
Serial.println("fout gezien");
}
*/
}
void input(){
if (Serial.available() == 0){
return;
}
rx_str = "";
rx_byte = "";
stringTel = 0;
for (int localTel1 = 0;localTel1 < 5;localTel1++){
inputStrings[localTel1] = "";
}
while (Serial.available() > 0){
rx_byte = Serial.read();
delay(30);
if (rx_byte == ','){
Serial.println("komma gespot");
stringTel = stringTel + 1 ;
Serial.println(stringTel);
rx_byte= "";
rx_str = "";
Serial.print(rx_byte);
}
if (rx_byte != ""){
Serial.print(rx_byte);
rx_str += rx_byte;
inputStrings[stringTel] = inputStrings[stringTel] + rx_byte;
// Serial.print("array : ");
// Serial.println(stringTel);
// Serial.println(inputStrings[stringTel]);
}
}
Serial.println("einde invoer");
for (int localTel2 = 0; localTel2 < 3;localTel2++){
Serial.print("output: ");
Serial.println(localTel2);
Serial.println (inputStrings[localTel2]);
}
}