char inputBuffer[50]; // Buffer to store incoming data
int buffIndex = 0; // Index to keep track of where to store the next character
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[buffIndex] = '\0'; // Null-terminate the string
Serial.print("You entered: ");
Serial.println(inputBuffer);
buffIndex = 0; // Reset index for the next input
} else {
inputBuffer[buffIndex++] = incomingByte;
if (buffIndex >= sizeof(inputBuffer) - 1) {
buffIndex = sizeof(inputBuffer) - 1;
}
}
}
}