File: CharacterAnalysis.ino

package info (click to toggle)
arduino 1%3A1.0.1%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 22,476 kB
  • sloc: java: 56,088; cpp: 10,050; ansic: 9,904; makefile: 1,721; xml: 468; perl: 198; sh: 153; python: 62
file content (83 lines) | stat: -rw-r--r-- 2,112 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
  Character analysis operators 
 
 Examples using the character analysis operators.
 Send any byte and the sketch will tell you about it.
 
 created 29 Nov 2010
 modified 2 Apr 2012
 by Tom Igoe
 
 This example code is in the public domain.
 */

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // 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();
  }
}