Pages: [1]   Go Down
Author Topic: Using print() with spaces between data on 1 line  (Read 1703 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
Karma: 0
Posts: 81
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How can print() be used to print several fields of data on one line, with spaces between each field of data?   for instance:

  Serial.print("\t");              // prints a tab





Will this print a row of words 1 - 5 on one line, with spaces between each word.  

What will print("\t");  produce?

Or could one print() be used in front of the words which are seperated by a colon or a comma?  such as:

print("word1", "word2"," word3", "word4", "word5");

PO'T  :-?

Spokane, Washington
Offline Offline
God Member
Karma: 1
Posts: 686
My name is Bob, and I'm an addict.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can use it like so:
Serial.print("word1 \t");
Serial.print("word2 \t");

Make sure you add that space, that will work for the space, or you can add another line, just for that space:
Serial.print(" ");

If you use Serial.print alot, you should look into the Streaming library, it's mighty fancy! lol can turn the above, into pretty much:

Serial << "word1" << " " << "\t" << "word2" << " " <<"\t" << "word3" << endl;
or isntead of endl, original Serial.println();

or of course:
Serial << "word1 \t" << "word2 \t" << "word3 \t" << endl;

And the awesome thing about it.. it adds 0 bytes on top of your sketch, it just adds a variation of the "print" library, for Serial.print etc it's awesome.

Here's the link, and more examples:

Pages: [1]   Go Up
Jump to: