Sending text a variable and text in single serial.write()

In C++ I would write:
Serial.write("Some text" + variable + "another text")
How to do this in a Arduino sketch?
Thanks

The following will do exactly the same as what you want:

Serial.print("Some text");
Serial.print(variable);
Serial.print("another text")

Serial.print() places data in a buffer so there is no benefit in using one text.

Else use a character array. Place the text in there with snprintf(). Next send that character array with Serial.write().

Doing so in C++ would result in doing math on pointers and not concatenating the text...

Using the String class would work but we would not recommend it because of the increased memory footprint and dynamic allocation.

@sterretje's solution is what would be recommended

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