Hello
I wantaed to take the name and phone number of clients and store it on an array but while (Serial.available()==0) is not waiting me. It goes toes to another execution before I give any input. What could be the problem? here is my code
void Regular(){
Serial.println(F("case R"));
Serial.print(F("name: "));
while (Serial.available()==0){
}
regular[n][1]=Serial.readString();
Serial.println(regular[n][1]);
Serial.print(F("phone_num: "));
while (Serial.available()==0){
}
regular[n][2]=Serial.readString();
Serial.println(regular[n][2]);
}
It would not do this if the serial buffer was empty. So there are some characters from the previous input in the buffer. Do you work with serial before this function?
Do not show a snippets, always show a complete code.
Yes... because what you are telling the serial monitor is to add some characters onto what you type... if you do this you need to handle those extra characters. Easiest solution is to use "No line ending". 2nd easiest... as @b707 has suggested.. after you get what you want, flush everything else the buffer before waiting for the next character.