Why to end with Serial.println?

Serial.print("x: ");
Serial.print(x);
Serial.print("\t");
Serial.print("y: ");
Serial.println(y);
delay(500);

why are we using serial.println for the last line?

I tried to incorporate serial.println for the x axis of my joystick code too and it messed up the format.

I'm still a noob when it comes to coding and arduino so idk why we're ending it with ln and not print only

I also tried to use print only for the y one and ended it with ("\t");

But it just displayed them both with gaps in between and in a single line.

So what I'm concluding with this is that no matter how many variables I add,
I've to end it with the ln for the last one to get them in proper alignment?

More like they're all connected to eachother and the last one decides how it's going to display?

https://docs.arduino.cc/language-reference/en/functions/communication/Serial/println/

and \t is the tabulator character

1 Like

Please post the exact "messed up" code!

It look like the TAB version of a CSV line.
TAB separated variables terminated with a NEWLINE.
I use it when the variables may contain a comma.

1 Like

I use this for simple joystick input to my flight simulator.
I use commas, but some code requires tabs.
FlightGear simulator allows the user to select the separator.

1 Like

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