1 | /*
|
---|
2 | ASCII table
|
---|
3 |
|
---|
4 | Prints out byte values in all possible formats:
|
---|
5 | * as raw binary values
|
---|
6 | * as ASCII-encoded decimal, hex, octal, and binary values
|
---|
7 |
|
---|
8 | For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
|
---|
9 |
|
---|
10 | The circuit: No external hardware needed.
|
---|
11 |
|
---|
12 | created 2006
|
---|
13 | by Nicholas Zambetti
|
---|
14 | http://www.zambetti.com
|
---|
15 | modified 9 Apr 2012
|
---|
16 | by Tom Igoe
|
---|
17 | modified 22 May 2013
|
---|
18 | by Cristian Maglie
|
---|
19 |
|
---|
20 | This example code is in the public domain.
|
---|
21 |
|
---|
22 | http://arduino.cc/en/Tutorial/ConsoleAsciiTable
|
---|
23 |
|
---|
24 | */
|
---|
25 |
|
---|
26 | #include <Console.h>
|
---|
27 |
|
---|
28 | void setup() {
|
---|
29 | //Initialize Console and wait for port to open:
|
---|
30 | Bridge.begin();
|
---|
31 | Console.begin();
|
---|
32 |
|
---|
33 | // Uncomment the following line to enable buffering:
|
---|
34 | // - better transmission speed and efficiency
|
---|
35 | // - needs to call Console.flush() to ensure that all
|
---|
36 | // transmitted data is sent
|
---|
37 |
|
---|
38 | //Console.buffer(64);
|
---|
39 |
|
---|
40 | while (!Console) {
|
---|
41 | ; // wait for Console port to connect.
|
---|
42 | }
|
---|
43 |
|
---|
44 | // prints title with ending line break
|
---|
45 | Console.println("ASCII Table ~ Character Map");
|
---|
46 | }
|
---|
47 |
|
---|
48 | // first visible ASCIIcharacter '!' is number 33:
|
---|
49 | int thisByte = 33;
|
---|
50 | // you can also write ASCII characters in single quotes.
|
---|
51 | // for example. '!' is the same as 33, so you could also use this:
|
---|
52 | //int thisByte = '!';
|
---|
53 |
|
---|
54 | void loop() {
|
---|
55 | // prints value unaltered, i.e. the raw binary version of the
|
---|
56 | // byte. The Console monitor interprets all bytes as
|
---|
57 | // ASCII, so 33, the first number, will show up as '!'
|
---|
58 | Console.write(thisByte);
|
---|
59 |
|
---|
60 | Console.print(", dec: ");
|
---|
61 | // prints value as string as an ASCII-encoded decimal (base 10).
|
---|
62 | // Decimal is the default format for Console.print() and Console.println(),
|
---|
63 | // so no modifier is needed:
|
---|
64 | Console.print(thisByte);
|
---|
65 | // But you can declare the modifier for decimal if you want to.
|
---|
66 | //this also works if you uncomment it:
|
---|
67 |
|
---|
68 | // Console.print(thisByte, DEC);
|
---|
69 |
|
---|
70 | Console.print(", hex: ");
|
---|
71 | // prints value as string in hexadecimal (base 16):
|
---|
72 | Console.print(thisByte, HEX);
|
---|
73 |
|
---|
74 | Console.print(", oct: ");
|
---|
75 | // prints value as string in octal (base 8);
|
---|
76 | Console.print(thisByte, OCT);
|
---|
77 |
|
---|
78 | Console.print(", bin: ");
|
---|
79 | // prints value as string in binary (base 2)
|
---|
80 | // also prints ending line break:
|
---|
81 | Console.println(thisByte, BIN);
|
---|
82 |
|
---|
83 | // if printed last visible character '~' or 126, stop:
|
---|
84 | if (thisByte == 126) { // you could also use if (thisByte == '~') {
|
---|
85 | // ensure the latest bit of data is sent
|
---|
86 | Console.flush();
|
---|
87 |
|
---|
88 | // This loop loops forever and does nothing
|
---|
89 | while (true) {
|
---|
90 | continue;
|
---|
91 | }
|
---|
92 | }
|
---|
93 | // go on to the next character
|
---|
94 | thisByte++;
|
---|
95 | }
|
---|