| 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 <http://www.zambetti.com> |
| 14 |
modified 9 Apr 2012 |
| 15 |
by Tom Igoe |
| 16 |
|
| 17 |
This example code is in the public domain. |
| 18 |
|
| 19 |
https://www.arduino.cc/en/Tutorial/BuiltInExamples/ASCIITable |
| 20 |
*/ |
| 21 |
|
| 22 |
void setup() { |
| 23 |
//Initialize serial and wait for port to open: |
| 24 |
Serial.begin(9600); |
| 25 |
while (!Serial) { |
| 26 |
; // wait for serial port to connect. Needed for native USB port only |
| 27 |
} |
| 28 |
|
| 29 |
// prints title with ending line break |
| 30 |
Serial.println("ASCII Table ~ Character Map"); |
| 31 |
} |
| 32 |
|
| 33 |
// first visible ASCIIcharacter '!' is number 33: |
| 34 |
int thisByte = 33; |
| 35 |
// you can also write ASCII characters in single quotes. |
| 36 |
// for example, '!' is the same as 33, so you could also use this: |
| 37 |
// int thisByte = '!'; |
| 38 |
|
| 39 |
void loop() { |
| 40 |
// prints value unaltered, i.e. the raw binary version of the byte. |
| 41 |
// The Serial Monitor interprets all bytes as ASCII, so 33, the first number, |
| 42 |
// will show up as '!' |
| 43 |
Serial.write(thisByte); |
| 44 |
|
| 45 |
Serial.print(", dec: "); |
| 46 |
// prints value as string as an ASCII-encoded decimal (base 10). |
| 47 |
// Decimal is the default format for Serial.print() and Serial.println(), |
| 48 |
// so no modifier is needed: |
| 49 |
Serial.print(thisByte); |
| 50 |
// But you can declare the modifier for decimal if you want to. |
| 51 |
// this also works if you uncomment it: |
| 52 |
|
| 53 |
// Serial.print(thisByte, DEC); |
| 54 |
|
| 55 |
|
| 56 |
Serial.print(", hex: "); |
| 57 |
// prints value as string in hexadecimal (base 16): |
| 58 |
Serial.print(thisByte, HEX); |
| 59 |
|
| 60 |
Serial.print(", oct: "); |
| 61 |
// prints value as string in octal (base 8); |
| 62 |
Serial.print(thisByte, OCT); |
| 63 |
|
| 64 |
Serial.print(", bin: "); |
| 65 |
// prints value as string in binary (base 2) also prints ending line break: |
| 66 |
Serial.println(thisByte, BIN); |
| 67 |
|
| 68 |
// if printed last visible character '~' or 126, stop: |
| 69 |
if (thisByte == 126) { // you could also use if (thisByte == '~') { |
| 70 |
// This loop loops forever and does nothing |
| 71 |
while (true) { |
| 72 |
continue; |
| 73 |
} |
| 74 |
} |
| 75 |
// go on to the next character |
| 76 |
thisByte++; |
| 77 |
} |