Created
February 22, 2018 20:04
-
-
Save funvill/c933006903d7b25a58680d277c1fc1d2 to your computer and use it in GitHub Desktop.
Arduino serial print sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Uses a FOR loop for data and prints a number 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("DEC"); | |
Serial.print("\t"); | |
Serial.print("HEX"); | |
Serial.print("\t"); | |
Serial.print("OCT"); | |
Serial.print("\t"); | |
Serial.print("BIN"); | |
Serial.print("\t"); | |
for(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"); // prints a tab | |
Serial.print(x, DEC); // print as an ASCII-encoded decimal | |
Serial.print("\t"); // prints a tab | |
Serial.print(x, HEX); // print as an ASCII-encoded hexadecimal | |
Serial.print("\t"); // prints a tab | |
Serial.print(x, OCT); // print as an ASCII-encoded octal | |
Serial.print("\t"); // prints a tab | |
Serial.println(x, BIN); // print as an ASCII-encoded binary | |
// then adds the carriage return with "println" | |
delay(200); // delay 200 milliseconds | |
} | |
Serial.println(""); // prints another carriage return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment