I'm working on a project where I'm displaying time (with the time library without external parts) on an I2C display. I want to save the most recent line from the serial monitor into a String for later use.
Serial.readString() waits up to 1000 msec (the default timeout value) before returning so it is busy waiting and then when it returns, time has elapsed so you code appears to jump. Try testing for any characters available and then reading them in one by one instead. If you encounter the last character which is usually a newline, then process the input.
It's advisable to forget that String (capital S) exists. Heavy use of it will result in holes in your memory and as a result hard to find issues at run time.
Read Robin's Serial Input Basics thread for a solid approach to serial communication; it uses so-called c-strings instead of String.
sterretje:
Read Robin's Serial Input Basics thread for a solid approach to serial communication; it uses so-called c-strings instead of String.
I'm not looking for Serial input but rather at the stream produced by the time library every second from the Serial monitor. I want to save the most recent line to a variable. So far the examples I've seen have pertained to Serial input.
For some reason, I've dealt with a bunch of problems when trying to save the values within the program. There aren't any error messages, but it isn't giving out any values when I print it. I figured it would be easier to save the time values from the Serial monitor instead.