|
| 1 | +/* |
| 2 | + Character analysis operators |
| 3 | + |
| 4 | + Examples using the character analysis operators |
| 5 | + from WCharacter.h, by Hernando Barragan. |
| 6 | + Send any byte and the sketch will tell you about it. |
| 7 | + |
| 8 | + created 29 Nov 2010 |
| 9 | + by Tom Igoe |
| 10 | + |
| 11 | + This example code is in the public domain. |
| 12 | + */ |
| 13 | + |
| 14 | +#include <WCharacter.h> // include the character analysis library |
| 15 | + |
| 16 | +void setup() { |
| 17 | + // Open serial communications: |
| 18 | + Serial.begin(9600); |
| 19 | + |
| 20 | + // send an intro: |
| 21 | + Serial.println("send any byte and I'll tell you everything I can about it"); |
| 22 | + Serial.println(); |
| 23 | +} |
| 24 | + |
| 25 | +void loop() { |
| 26 | + // get any incoming bytes: |
| 27 | + if (Serial.available() > 0) { |
| 28 | + int thisChar = Serial.read(); |
| 29 | + |
| 30 | + // say what was sent: |
| 31 | + Serial.print("You sent me: \'"); |
| 32 | + Serial.write(thisChar); |
| 33 | + Serial.print("\' ASCII Value: "); |
| 34 | + Serial.println(thisChar); |
| 35 | + |
| 36 | + // analyze what was sent: |
| 37 | + if(isAlphaNumeric(thisChar)) { |
| 38 | + Serial.println("it's alphanumeric"); |
| 39 | + } |
| 40 | + if(isAlpha(thisChar)) { |
| 41 | + Serial.println("it's alphabetic"); |
| 42 | + } |
| 43 | + if(isAscii(thisChar)) { |
| 44 | + Serial.println("it's ASCII"); |
| 45 | + } |
| 46 | + if(isWhitespace(thisChar)) { |
| 47 | + Serial.println("it's whitespace"); |
| 48 | + } |
| 49 | + if(isControl(thisChar)) { |
| 50 | + Serial.println("it's a control character"); |
| 51 | + } |
| 52 | + if(isDigit(thisChar)) { |
| 53 | + Serial.println("it's a numeric digit"); |
| 54 | + } |
| 55 | + if(isGraph(thisChar)) { |
| 56 | + Serial.println("it's a printable character that's not whitespace"); |
| 57 | + } |
| 58 | + if(isLowerCase(thisChar)) { |
| 59 | + Serial.println("it's lower case"); |
| 60 | + } |
| 61 | + if(isPrintable(thisChar)) { |
| 62 | + Serial.println("it's printable"); |
| 63 | + } |
| 64 | + if(isPunct(thisChar)) { |
| 65 | + Serial.println("it's punctuation"); |
| 66 | + } |
| 67 | + if(isSpace(thisChar)) { |
| 68 | + Serial.println("it's a space character"); |
| 69 | + } |
| 70 | + if(isUpperCase(thisChar)) { |
| 71 | + Serial.println("it's upper case"); |
| 72 | + } |
| 73 | + if (isHexadecimalDigit(thisChar)) { |
| 74 | + Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)"); |
| 75 | + } |
| 76 | + |
| 77 | + // add some space and ask for another byte: |
| 78 | + Serial.println(); |
| 79 | + Serial.println("Give me another byte:"); |
| 80 | + Serial.println(); |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
0 commit comments