Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added example for WCharacter.h functions in String examples
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
build/shared/examples/8.Strings/CharacterAnalysis/CharacterAnalysis.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
Character analysis operators | ||
Examples using the character analysis operators | ||
from WCharacter.h, by Hernando Barragan. | ||
Send any byte and the sketch will tell you about it. | ||
created 29 Nov 2010 | ||
by Tom Igoe | ||
This example code is in the public domain. | ||
*/ | ||
|
||
#include <WCharacter.h> // include the character analysis library | ||
|
||
void setup() { | ||
// Open serial communications: | ||
Serial.begin(9600); | ||
|
||
// 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: | ||
if(isAlphaNumeric(thisChar)) { | ||
Serial.println("it's alphanumeric"); | ||
} | ||
if(isAlpha(thisChar)) { | ||
Serial.println("it's alphabetic"); | ||
} | ||
if(isAscii(thisChar)) { | ||
Serial.println("it's ASCII"); | ||
} | ||
if(isWhitespace(thisChar)) { | ||
Serial.println("it's whitespace"); | ||
} | ||
if(isControl(thisChar)) { | ||
Serial.println("it's a control character"); | ||
} | ||
if(isDigit(thisChar)) { | ||
Serial.println("it's a numeric digit"); | ||
} | ||
if(isGraph(thisChar)) { | ||
Serial.println("it's a printable character that's not whitespace"); | ||
} | ||
if(isLowerCase(thisChar)) { | ||
Serial.println("it's lower case"); | ||
} | ||
if(isPrintable(thisChar)) { | ||
Serial.println("it's printable"); | ||
} | ||
if(isPunct(thisChar)) { | ||
Serial.println("it's punctuation"); | ||
} | ||
if(isSpace(thisChar)) { | ||
Serial.println("it's a space character"); | ||
} | ||
if(isUpperCase(thisChar)) { | ||
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(); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|