String Concatenation & Output

Hiya folks.

Just wondering how to get a bunch of feedback to the Serial Monitor. I have floats, integers, and strings, and want to output something like this:

String myOutput = "alpha: " + String(alpha) + "/bravo: " + String(bravo) + "/charlie: " + String(charlie);

I've been trying to coerce everything into a single string but that hasn't worked. Any pointers on coercion and syntax rules for String output? I'd like to have a look at my variables every second or so through the loop.

Cheers

try

String myOutput = "alpha" + alpha
myOutput = myOutput + "bravo"
myOutput = myOutput + bravo

This works. It might not be the fastest way, but it works.
But if you want to print tothe serial port, why don't you just do

Serial.print("alpha");
Serial.print(alpha);
Serial.print("/Bravo");
Serial.println(bravo);

Hi there. The problem with the latter option is that it comes out on different lines. I want to provide all information on a single line. Also, this doesn't work:

String myF = "R1" + R1; // invalid operands of types 'const char [3]' and 'float' to binary 'operator+'

R1 is a float. So I tried coercing float R1 to a string using:

String myF = "R1" + String(R1); // doesn't work

Not sure how to just bring everything into a string.

The problem with the latter option is that it comes out on different lines.

No, it doesn't. Serial.print() does not send a carriage return/line feed, so successive Serial.print()s are all on the same line. Serial.println() does send CR/LF, so is used for the last element of the line.

Oh I completely missed that! OK then, I'll give it a whirl. Thanks for the heads up. I should study the Reference some more. Heh.

Cheers