2011-08-30 21:33:32 +02:00
|
|
|
/*
|
|
|
|
ASCII table
|
2013-10-21 09:58:40 +02:00
|
|
|
|
|
|
|
Prints out byte values in all possible formats:
|
2011-08-30 21:33:32 +02:00
|
|
|
* as raw binary values
|
|
|
|
* as ASCII-encoded decimal, hex, octal, and binary values
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2011-08-30 21:33:32 +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
|
|
|
|
2011-08-30 21:33:32 +02:00
|
|
|
The circuit: No external hardware needed.
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2011-08-30 21:33:32 +02:00
|
|
|
created 2006
|
2013-10-21 09:58:40 +02:00
|
|
|
by Nicholas Zambetti
|
2012-04-09 15:51:35 +02:00
|
|
|
modified 9 Apr 2012
|
2011-08-30 21:33:32 +02:00
|
|
|
by Tom Igoe
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2011-08-30 21:33:32 +02:00
|
|
|
This example code is in the public domain.
|
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
<http://www.zambetti.com>
|
|
|
|
|
2011-08-30 21:33:32 +02:00
|
|
|
*/
|
2013-10-21 09:58:40 +02:00
|
|
|
void setup() {
|
|
|
|
//Initialize serial and wait for port to open:
|
|
|
|
Serial.begin(9600);
|
2012-04-09 15:51:35 +02:00
|
|
|
while (!Serial) {
|
|
|
|
; // wait for serial port to connect. Needed for Leonardo only
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
|
|
|
|
// prints title with ending line break
|
|
|
|
Serial.println("ASCII Table ~ Character Map");
|
|
|
|
}
|
2011-08-30 21:33:32 +02:00
|
|
|
|
|
|
|
// first visible ASCIIcharacter '!' is number 33:
|
2013-10-21 09:58:40 +02:00
|
|
|
int thisByte = 33;
|
2011-08-30 21:33:32 +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 = '!';
|
2011-08-30 21:33:32 +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 serial monitor interprets all bytes as
|
|
|
|
// ASCII, so 33, the first number, will show up as '!'
|
|
|
|
Serial.write(thisByte);
|
2011-08-30 21:33:32 +02:00
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(", dec: ");
|
2011-08-30 21:33:32 +02:00
|
|
|
// prints value as string as an ASCII-encoded decimal (base 10).
|
|
|
|
// Decimal is the default format for Serial.print() and Serial.println(),
|
|
|
|
// so no modifier is needed:
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(thisByte);
|
2011-08-30 21:33:32 +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
|
|
|
// Serial.print(thisByte, DEC);
|
2011-08-30 21:33:32 +02:00
|
|
|
|
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(", hex: ");
|
2011-08-30 21:33:32 +02:00
|
|
|
// prints value as string in hexadecimal (base 16):
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(thisByte, HEX);
|
2011-08-30 21:33:32 +02:00
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(", oct: ");
|
2011-08-30 21:33:32 +02:00
|
|
|
// prints value as string in octal (base 8);
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(thisByte, OCT);
|
2011-08-30 21:33:32 +02:00
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(", bin: ");
|
|
|
|
// prints value as string in binary (base 2)
|
2011-08-30 21:33:32 +02:00
|
|
|
// also prints ending line break:
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.println(thisByte, BIN);
|
2011-08-30 21:33:32 +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 == '~') {
|
2011-08-30 21:33:32 +02:00
|
|
|
// This loop loops forever and does nothing
|
2013-10-21 09:58:40 +02:00
|
|
|
while (true) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-08-30 21:33:32 +02:00
|
|
|
// go on to the next character
|
2013-10-21 09:58:40 +02:00
|
|
|
thisByte++;
|
|
|
|
}
|