print multiple variables amount in one line

hi
I want to print several variables which all of them are double , in same line. actually if I have a, b and c as variables what I want to show is
a b c
edit:
if I use

Serial.println(a)
Serial.println(b)
Serial.println(c)

it shows :
a
b
c
and if I use

Serial.println(a,b,c)

it does not show the correct result

Have you tried this?

Serial.print(a)
Serial.print(b)
Serial.print(c)
Serial.print(a);
Serial.print(",");
Serial.print(b);
Serial.print(",");
Serial.println(c);
2 Likes

BJHenry:
Have you tried this?

Serial.print(a)

Serial.print(b)
Serial.print(c)

thanks a lot

PaulRB:

Serial.print(a);

Serial.print(",");
Serial.print(b);
Serial.print(",");
Serial.println(c);

thanks a lot

1 Like

one answer is that way as BJHenry and PaulRB said, but there is another way which is faster than serial.print

String p1=";";
Serial.println(a + p1 + b + p1 + c);

it shows this result:
a;b;c

koronus:
one answer is that way as BJHenry and PaulRB said, but there is another way which is faster than serial.print

String p1=";";

Serial.println(a + p1 + b + p1 + c);



it shows this result:
a;b;c

That may be the case, but using String on something like an Arduino isn't good practice.

Delta_G:
Also can make Swiss cheese out of RAM because no garbage collection on little micro. Can crash programs and lock up boards and all that stuff.

I don't think that's true in this case. String p1 is never resized, and all other Strings that are created are temporaries. During the lifetime of these Strings, no other dynamic memory allocation happens, so no fragmentation happens.

But I do agree that it's not a good idea, even if it's not a problem in this specific case.


When I have to do a lot of printing, I use this PrintSteam utility library:

int a = 1, b = 2, c = 3;
Serial << a << ", " << b << ", " << c << endl;

This prints: 1, 2, 3

I also often use this Arduino-Debugging "library":

int a = 1, b = 2, c = 3;
DEBUGVAL( a, b, c );

This prints: a = 1, b = 2, c = 3.

Pieter