Int values go to 0

Hi everyone, this is my first post. I'm sorry for my English, I'm from South America. I'm programming this code, where I input 2 values in the serial port (x and y) to save them in two int variables.

int x;
int y;
#define PRINT(a) Serial.println(a);

void setup()
{
Serial.begin(9600);
Serial.setTimeout(10);
}
void loop()
{  
if (Serial.available()>0){
String xString = Serial.readStringUntil(',');
String yString = Serial.readStringUntil(';');
x = xString.toInt();
y = yString.toInt();
Serial.print("X: ");
PRINT(x);
Serial.print("Y: ");
PRINT(y);
}
}

When I write the values, it works fine and prints back the values, but then it prints 0. I don't know why does that happen or how to fix it, so i would really appreciate if you could help me, because I need to finish this code as soon as possible.

it occurs because your line do not stops in ";", it contains one or two hidden line terminators.
Turn off line terminators in the bottom of PC Monitor window:

line endings small

Try setting the line endings in serial monitor to No line ending.

Ohh it works perfectly now! thank you <3

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.