Hi, everyone. I am begginer and I have a problem in my code:
It is a code that, when typing something on the serial monitor, it writes the number of characters in the variable.
When I type, it always shows an extra value in length ().
Example: when typing and sending "1234567", it shows length () = 8 and not 7.
Would anyone know why? Thanks for the answer!
String d;
void setup() {
Serial.begin(115200);
}
void loop() {
if (Serial.available() > 0) {
d = "";
while (Serial.available() > 0) {
//FAZ A LEITURA DA SERIAL E ARMAZENA NA VARIÁVEL LOCAL (CHAR)
char ch = Serial.read();
//COLOCA O RESULTADO NUMA VARIÁVEL GLOBAL (STRING)
d += ch;
//Serial.print(ch);
}
Serial.println("Length:");
Serial.println(d.length());
}
}
teste_string.ino (454 Bytes)