~ubuntu-branches/debian/experimental/arduino/experimental

« back to all changes in this revision

Viewing changes to build/shared/examples/4.Communication/ASCIITable/ASCIITable.pde

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2012-03-11 18:19:42 UTC
  • mfrom: (1.1.5) (5.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120311181942-be2clnbz1gcehixb
Tags: 1:1.0.1~rc1+dfsg-1
New upstream release, experimental.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  ASCII table
3
 
 
4
 
 Prints out byte values in all possible formats:  
5
 
 * as raw binary values
6
 
 * as ASCII-encoded decimal, hex, octal, and binary values
7
 
 
8
 
 For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
9
 
 
10
 
 The circuit:  No external hardware needed.
11
 
 
12
 
 created 2006
13
 
 by Nicholas Zambetti 
14
 
 modified 18 Jan 2009
15
 
 by Tom Igoe
16
 
 
17
 
 This example code is in the public domain.
18
 
 
19
 
 <http://www.zambetti.com> 
20
 
 
21
 
 */
22
 
void setup() 
23
 
24
 
  Serial.begin(9600); 
25
 
 
26
 
  // prints title with ending line break 
27
 
  Serial.println("ASCII Table ~ Character Map"); 
28
 
29
 
 
30
 
// first visible ASCIIcharacter '!' is number 33:
31
 
int thisByte = 33; 
32
 
// you can also write ASCII characters in single quotes.
33
 
// for example. '!' is the same as 33, so you could also use this:
34
 
//int thisByte = '!';  
35
 
 
36
 
void loop() 
37
 
38
 
  // prints value unaltered, i.e. the raw binary version of the 
39
 
  // byte. The serial monitor interprets all bytes as 
40
 
  // ASCII, so 33, the first number,  will show up as '!' 
41
 
  Serial.write(thisByte);    
42
 
 
43
 
  Serial.print(", dec: "); 
44
 
  // prints value as string as an ASCII-encoded decimal (base 10).
45
 
  // Decimal is the  default format for Serial.print() and Serial.println(),
46
 
  // so no modifier is needed:
47
 
  Serial.print(thisByte);      
48
 
  // But you can declare the modifier for decimal if you want to.
49
 
  //this also works if you uncomment it:
50
 
 
51
 
  // Serial.print(thisByte, DEC);  
52
 
 
53
 
 
54
 
  Serial.print(", hex: "); 
55
 
  // prints value as string in hexadecimal (base 16):
56
 
  Serial.print(thisByte, HEX);     
57
 
 
58
 
  Serial.print(", oct: "); 
59
 
  // prints value as string in octal (base 8);
60
 
  Serial.print(thisByte, OCT);     
61
 
 
62
 
  Serial.print(", bin: "); 
63
 
  // prints value as string in binary (base 2) 
64
 
  // also prints ending line break:
65
 
  Serial.println(thisByte, BIN);   
66
 
 
67
 
  // if printed last visible character '~' or 126, stop: 
68
 
  if(thisByte == 126) {     // you could also use if (thisByte == '~') {
69
 
    // This loop loops forever and does nothing
70
 
    while(true) { 
71
 
      continue; 
72
 
    } 
73
 
  } 
74
 
  // go on to the next character
75
 
  thisByte++;  
76