Back to the original problem... I almost got it. I still have a couple of questions (below!);
Here's the code:
char Name[9] = ""; // My Data array
char inChar; // Where to store the character read
byte index = 0; // Index into array; where to store the character
void setup(){
Serial.begin(9600);
}
void loop(){
if (Serial.available()>0){
inChar = Serial.read();
Name[index] = inChar; // Store it
if (index>8){
Serial.println("Invalid Input, please enter 3 to 8 characters");
index=-1;
memset(Name, 0, sizeof(Name));
}
else if (int(Name[index])==13){ //If Carriage return has been reached
Serial.println(Name);
index=-1;
Name[9] = '\0';
memset(Name, 0, sizeof(Name));
}
index++; // Increment where to write next
}
}
If I insert any string from 1 to 8 chars it works perfectly, else:
- 9 chars - println the error message - GREAT!
-
9 chars - sometimes prints error message twice (more than 20 chars) or error message + modulos 10 (that is the 11th, 12th, 13th... chars) - I don't get why? or how to avoid?
Thanks for your help so far!!