4
Prints out byte values in all possible formats:
6
* as ASCII-encoded decimal, hex, octal, and binary values
8
For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
10
The circuit: No external hardware needed.
17
This example code is in the public domain.
19
<http://www.zambetti.com>
26
// prints title with ending line break
27
Serial.println("ASCII Table ~ Character Map");
30
// first visible ASCIIcharacter '!' is number 33:
32
// you can also write ASCII characters in single quotes.
33
// for example. '!' is the same as 33, so you could also use this:
38
// prints value unaltered, i.e. the raw binary version of the
39
// byte. The serial monitor interprets all bytes as
40
// ASCII, so 33, the first number, will show up as '!'
41
Serial.write(thisByte);
43
Serial.print(", dec: ");
44
// prints value as string as an ASCII-encoded decimal (base 10).
45
// Decimal is the default format for Serial.print() and Serial.println(),
46
// so no modifier is needed:
47
Serial.print(thisByte);
48
// But you can declare the modifier for decimal if you want to.
49
//this also works if you uncomment it:
51
// Serial.print(thisByte, DEC);
54
Serial.print(", hex: ");
55
// prints value as string in hexadecimal (base 16):
56
Serial.print(thisByte, HEX);
58
Serial.print(", oct: ");
59
// prints value as string in octal (base 8);
60
Serial.print(thisByte, OCT);
62
Serial.print(", bin: ");
63
// prints value as string in binary (base 2)
64
// also prints ending line break:
65
Serial.println(thisByte, BIN);
67
// if printed last visible character '~' or 126, stop:
68
if(thisByte == 126) { // you could also use if (thisByte == '~') {
69
// This loop loops forever and does nothing
74
// go on to the next character