Skip to content

Improve Serial.print() page #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions Language/Functions/Communication/Serial/print.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ An optional second parameter specifies the base (format) to use; permitted value
* `Serial.print(78, OCT) gives "116"` +
* `Serial.print(78, DEC) gives "78"` +
* `Serial.print(78, HEX) gives "4E"` +
* `Serial.println(1.23456, 0) gives "1"` +
* `Serial.println(1.23456, 2) gives "1.23"` +
* `Serial.println(1.23456, 4) gives "1.2346"`
* `Serial.print(1.23456, 0) gives "1"` +
* `Serial.print(1.23456, 2) gives "1.23"` +
* `Serial.print(1.23456, 4) gives "1.2346"`

You can pass flash-memory based strings to Serial.print() by wrapping them with F(). For example:
You can pass flash-memory based strings to Serial.print() by wrapping them with link:../../../../variables/utilities/progmem[F()]. For example:

`Serial.print(F(“Hello World”))`

To send a single byte, use link:../write[Serial.write()].
To send data without conversion to its representation as characters, use link:../write[Serial.write()].
[%hardbreaks]


Expand Down Expand Up @@ -71,18 +71,16 @@ To send a single byte, use link:../write[Serial.write()].
[source,arduino]
----
/*
Uses a FOR loop for data and prints a number in various formats.
Uses a for loop to print numbers in various formats.
*/
int x = 0; // variable

void setup() {
Serial.begin(9600); // open the serial port at 9600 bps:
}

void loop() {
// print labels
Serial.print("NO FORMAT"); // prints a label
Serial.print("\t"); // prints a tab
Serial.print("NO FORMAT"); // prints a label
Serial.print("\t"); // prints a tab

Serial.print("DEC");
Serial.print("\t");
Expand All @@ -94,10 +92,9 @@ void loop() {
Serial.print("\t");

Serial.print("BIN");
Serial.println("\t"); // carriage return after the last label

for(x=0; x< 64; x++){ // only part of the ASCII chart, change to suit
Serial.println(); // carriage return after the last label

for (int x = 0; x < 64; x++) { // only part of the ASCII chart, change to suit
// print it out in many formats:
Serial.print(x); // print as an ASCII-encoded decimal - same as "DEC"
Serial.print("\t\t"); // prints two tabs to accomodate the label lenght
Expand All @@ -112,10 +109,10 @@ void loop() {
Serial.print("\t"); // prints a tab

Serial.println(x, BIN); // print as an ASCII-encoded binary
// then adds the carriage return with "println"
// then adds the carriage return with "println"
delay(200); // delay 200 milliseconds
}
Serial.println(""); // prints another carriage return
Serial.println(); // prints another carriage return
}
----
[%hardbreaks]
Expand Down