So I'm trying to run the script below as a test for reading from the serial. I open the serial monitor, write letters to it, type 'x' to see that it stored the letters. I now close the serial monitor, reopen it, then the L LED on my Arduino UNO flashes 4 times quickly, and then when I type "x" in the serial monitor, it's clear that the String variable values has reset. Is this normal? Am I running out of memory exactly when I reopen the serial monitor?
int val; // Value read from the serial port
String values = "";
void setup()
{
Serial.begin(9600);
//Serial.flush();
}
void loop()
{
// Read from serial port
if (Serial.available())
{
val = Serial.read();
values = values + (char) val;
if (val == 'x')
Serial.println(values);
}
}