2010-11-29 20:56:33 +01:00
|
|
|
/*
|
2013-10-21 09:58:40 +02:00
|
|
|
Character analysis operators
|
|
|
|
|
2010-12-04 05:12:41 +01:00
|
|
|
Examples using the character analysis operators.
|
2010-11-29 20:56:33 +01:00
|
|
|
Send any byte and the sketch will tell you about it.
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2010-11-29 20:56:33 +01:00
|
|
|
created 29 Nov 2010
|
2012-04-02 15:07:58 +02:00
|
|
|
modified 2 Apr 2012
|
2010-11-29 20:56:33 +01:00
|
|
|
by Tom Igoe
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2010-11-29 20:56:33 +01:00
|
|
|
This example code is in the public domain.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void setup() {
|
2012-04-02 15:07:58 +02:00
|
|
|
// Open serial communications and wait for port to open:
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.begin(9600);
|
2012-04-06 20:00:31 +02:00
|
|
|
while (!Serial) {
|
2015-09-21 14:44:19 +02:00
|
|
|
; // wait for serial port to connect. Needed for native USB port only
|
2012-04-06 20:00:31 +02:00
|
|
|
}
|
2010-11-29 20:56:33 +01:00
|
|
|
|
|
|
|
// send an intro:
|
|
|
|
Serial.println("send any byte and I'll tell you everything I can about it");
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
// get any incoming bytes:
|
|
|
|
if (Serial.available() > 0) {
|
|
|
|
int thisChar = Serial.read();
|
|
|
|
|
|
|
|
// say what was sent:
|
|
|
|
Serial.print("You sent me: \'");
|
|
|
|
Serial.write(thisChar);
|
|
|
|
Serial.print("\' ASCII Value: ");
|
|
|
|
Serial.println(thisChar);
|
|
|
|
|
|
|
|
// analyze what was sent:
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isAlphaNumeric(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's alphanumeric");
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isAlpha(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's alphabetic");
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isAscii(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's ASCII");
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isWhitespace(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's whitespace");
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isControl(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's a control character");
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isDigit(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's a numeric digit");
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isGraph(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's a printable character that's not whitespace");
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isLowerCase(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's lower case");
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isPrintable(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's printable");
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isPunct(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's punctuation");
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isSpace(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's a space character");
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (isUpperCase(thisChar)) {
|
2010-11-29 20:56:33 +01:00
|
|
|
Serial.println("it's upper case");
|
|
|
|
}
|
|
|
|
if (isHexadecimalDigit(thisChar)) {
|
|
|
|
Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// add some space and ask for another byte:
|
|
|
|
Serial.println();
|
|
|
|
Serial.println("Give me another byte:");
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
}
|