Skip to content

Commit dd79d73

Browse files
committed
Improve Serial.print() example code
- Improve heading comment. - A little better alignment of "prettified" inline comments. - Remove unnecessary trailing tab output. - Remove unnecessary global variable. - Remove unnecessary use of empty quotes in Serial.println(). - Auto Format!!!
1 parent cf6cd3a commit dd79d73

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Language/Functions/Communication/Serial/print.adoc

+7-10
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,16 @@ To send data without conversion to its representation as characters, use link:..
7171
[source,arduino]
7272
----
7373
/*
74-
Uses a FOR loop for data and prints a number in various formats.
74+
Uses a for loop to print numbers in various formats.
7575
*/
76-
int x = 0; // variable
77-
7876
void setup() {
7977
Serial.begin(9600); // open the serial port at 9600 bps:
8078
}
8179
8280
void loop() {
8381
// print labels
84-
Serial.print("NO FORMAT"); // prints a label
85-
Serial.print("\t"); // prints a tab
82+
Serial.print("NO FORMAT"); // prints a label
83+
Serial.print("\t"); // prints a tab
8684
8785
Serial.print("DEC");
8886
Serial.print("\t");
@@ -94,10 +92,9 @@ void loop() {
9492
Serial.print("\t");
9593
9694
Serial.print("BIN");
97-
Serial.println("\t"); // carriage return after the last label
98-
99-
for(x=0; x< 64; x++){ // only part of the ASCII chart, change to suit
95+
Serial.println(); // carriage return after the last label
10096
97+
for (int x = 0; x < 64; x++) { // only part of the ASCII chart, change to suit
10198
// print it out in many formats:
10299
Serial.print(x); // print as an ASCII-encoded decimal - same as "DEC"
103100
Serial.print("\t\t"); // prints two tabs to accomodate the label lenght
@@ -112,10 +109,10 @@ void loop() {
112109
Serial.print("\t"); // prints a tab
113110
114111
Serial.println(x, BIN); // print as an ASCII-encoded binary
115-
// then adds the carriage return with "println"
112+
// then adds the carriage return with "println"
116113
delay(200); // delay 200 milliseconds
117114
}
118-
Serial.println(""); // prints another carriage return
115+
Serial.println(); // prints another carriage return
119116
}
120117
----
121118
[%hardbreaks]

0 commit comments

Comments
 (0)