char message[600]; // Buffer to hold the message
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.setTimeout(500);
Serial.println("Type a message (end with Enter):");
}
void loop() {
// Serial.print("x ");
delay(10);
}
void serialEvent() {
uint16_t bytesRead;
do {
bytesRead = Serial.readBytesUntil('\n', message, sizeof(message) - 1);
} while(bytesRead == 0 || (message[0] == '<' && bytesRead == 1));
if (message[bytesRead - 1] == '<') {
bytesRead-- ;
}
message[bytesRead] = 0; // Null-terminate the string
Serial.println();
Serial.print(bytesRead);
Serial.print(" bytes message: ");
Serial.print(message);
Serial.println("«");
}