Error Outputting Values Arduino Serial.print I am experimenting with the following program I found online (with slight modifications):
int x;
void setup() {
 Serial.begin(9600);
 Serial.setTimeout(1);
}
void loop() {
 while (!Serial.available());
 x = Serial.readString().toInt();
 int y = x + 1;
 Serial.print(y);
}

I am encountering an error in Serial monitor output; if I input 1, I get 21 printed. I think what's happening is that every digit in a number gets incremented by 1, and then 1 is put at the end for some reason. For example, if I input 234, my output is 3451. I think the error lies with the line  x = Serial.readString().toInt();, but am unsure how to fix this. Thank you!
There's two problems here.
First, you don't enter &quot;234&quot;, you enter &quot;2&quot; followed by &quot;3&quot; and finally &quot;4&quot;. Your really small timeout doesn't give the digits enough time to arrive.
Second, your line ending is being received and interpreted as &quot;not a number&quot; which is returned as 0 by .toInt().
What you need to do is:

Don't set a short timeout - you can remove that line entirely.
Use .readStringUntil('\n') to read up until your line ending in one go.