2013-05-22 19:17:58 +02:00
|
|
|
/*
|
|
|
|
ASCII table
|
2013-10-21 09:58:40 +02:00
|
|
|
|
|
|
|
Prints out byte values in all possible formats:
|
2013-05-22 19:17:58 +02:00
|
|
|
* as raw binary values
|
|
|
|
* as ASCII-encoded decimal, hex, octal, and binary values
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-22 19:17:58 +02:00
|
|
|
For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-22 19:17:58 +02:00
|
|
|
The circuit: No external hardware needed.
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-22 19:17:58 +02:00
|
|
|
created 2006
|
2013-10-21 09:58:40 +02:00
|
|
|
by Nicholas Zambetti
|
2013-09-09 20:56:15 +02:00
|
|
|
http://www.zambetti.com
|
2013-05-22 19:17:58 +02:00
|
|
|
modified 9 Apr 2012
|
|
|
|
by Tom Igoe
|
|
|
|
modified 22 May 2013
|
|
|
|
by Cristian Maglie
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-22 19:17:58 +02:00
|
|
|
This example code is in the public domain.
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-09-09 20:56:15 +02:00
|
|
|
http://arduino.cc/en/Tutorial/ConsoleAsciiTable
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-22 19:17:58 +02:00
|
|
|
*/
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-22 19:17:58 +02:00
|
|
|
#include <Console.h>
|
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
void setup() {
|
|
|
|
//Initialize Console and wait for port to open:
|
2013-05-22 19:17:58 +02:00
|
|
|
Bridge.begin();
|
2013-10-21 09:58:40 +02:00
|
|
|
Console.begin();
|
|
|
|
|
2013-06-05 20:20:18 +02:00
|
|
|
// Uncomment the following line to enable buffering:
|
2013-05-22 19:17:58 +02:00
|
|
|
// - better transmission speed and efficiency
|
2013-10-21 09:58:40 +02:00
|
|
|
// - needs to call Console.flush() to ensure that all
|
2013-05-22 19:17:58 +02:00
|
|
|
// transmitted data is sent
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-22 19:17:58 +02:00
|
|
|
//Console.buffer(64);
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-22 19:17:58 +02:00
|
|
|
while (!Console) {
|
|
|
|
; // wait for Console port to connect.
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
|
|
|
|
// prints title with ending line break
|
|
|
|
Console.println("ASCII Table ~ Character Map");
|
|
|
|
}
|
2013-05-22 19:17:58 +02:00
|
|
|
|
|
|
|
// first visible ASCIIcharacter '!' is number 33:
|
2013-10-21 09:58:40 +02:00
|
|
|
int thisByte = 33;
|
2013-05-22 19:17:58 +02:00
|
|
|
// you can also write ASCII characters in single quotes.
|
|
|
|
// for example. '!' is the same as 33, so you could also use this:
|
2013-10-21 09:58:40 +02:00
|
|
|
//int thisByte = '!';
|
2013-05-22 19:17:58 +02:00
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
void loop() {
|
|
|
|
// prints value unaltered, i.e. the raw binary version of the
|
|
|
|
// byte. The Console monitor interprets all bytes as
|
|
|
|
// ASCII, so 33, the first number, will show up as '!'
|
|
|
|
Console.write(thisByte);
|
2013-05-22 19:17:58 +02:00
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
Console.print(", dec: ");
|
2013-05-22 19:17:58 +02:00
|
|
|
// prints value as string as an ASCII-encoded decimal (base 10).
|
|
|
|
// Decimal is the default format for Console.print() and Console.println(),
|
|
|
|
// so no modifier is needed:
|
2013-10-21 09:58:40 +02:00
|
|
|
Console.print(thisByte);
|
2013-05-22 19:17:58 +02:00
|
|
|
// But you can declare the modifier for decimal if you want to.
|
|
|
|
//this also works if you uncomment it:
|
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
// Console.print(thisByte, DEC);
|
2013-05-22 19:17:58 +02:00
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
Console.print(", hex: ");
|
2013-05-22 19:17:58 +02:00
|
|
|
// prints value as string in hexadecimal (base 16):
|
2013-10-21 09:58:40 +02:00
|
|
|
Console.print(thisByte, HEX);
|
2013-05-22 19:17:58 +02:00
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
Console.print(", oct: ");
|
2013-05-22 19:17:58 +02:00
|
|
|
// prints value as string in octal (base 8);
|
2013-10-21 09:58:40 +02:00
|
|
|
Console.print(thisByte, OCT);
|
2013-05-22 19:17:58 +02:00
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
Console.print(", bin: ");
|
|
|
|
// prints value as string in binary (base 2)
|
2013-05-22 19:17:58 +02:00
|
|
|
// also prints ending line break:
|
2013-10-21 09:58:40 +02:00
|
|
|
Console.println(thisByte, BIN);
|
2013-05-22 19:17:58 +02:00
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
// if printed last visible character '~' or 126, stop:
|
|
|
|
if (thisByte == 126) { // you could also use if (thisByte == '~') {
|
2013-06-05 20:20:18 +02:00
|
|
|
// ensure the latest bit of data is sent
|
|
|
|
Console.flush();
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-22 19:17:58 +02:00
|
|
|
// This loop loops forever and does nothing
|
2013-10-21 09:58:40 +02:00
|
|
|
while (true) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2013-05-22 19:17:58 +02:00
|
|
|
// go on to the next character
|
2013-10-21 09:58:40 +02:00
|
|
|
thisByte++;
|
|
|
|
}
|