char inputBuffer[5][50]; // Buffer to store incoming data
int buffIndex1 = 0; // Index to keep track of where to store the next character
int buffIndex2 = 0;
void setup() {
Serial.begin(9600);
Serial.println("char array tutorial");
Serial.println();
Serial.println("Type a string and terminate with RETURN");
Serial.println();
}
void loop() {
while (Serial.available() > 0) {
char incomingByte = Serial.read();
if (incomingByte == '\n') {
inputBuffer[buffIndex1][buffIndex2] = '\0'; // Null-terminate the string
Serial.print("You entered: ");
Serial.println(inputBuffer[buffIndex1]);
buffIndex2 = 0; // Reset index for the next input
} else {
inputBuffer[buffIndex1][buffIndex2++] = incomingByte;
if (buffIndex2 >= sizeof(inputBuffer) - 1) {
buffIndex2 = sizeof(inputBuffer) - 1;
}
}
}
}