~ubuntu-branches/ubuntu/precise/arduino/precise

« back to all changes in this revision

Viewing changes to examples/Communication/ASCIITable/ASCIITable.pde

  • Committer: Bazaar Package Importer
  • Author(s): Scott Howard
  • Date: 2010-04-13 22:32:24 UTC
  • Revision ID: james.westby@ubuntu.com-20100413223224-jduxnd0xxnkkda02
Tags: upstream-0018+dfsg
ImportĀ upstreamĀ versionĀ 0018+dfsg

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
 <http://www.zambetti.com> 
 
18
 */
 
19
void setup() 
 
20
 
21
  Serial.begin(9600); 
 
22
 
 
23
  // prints title with ending line break 
 
24
  Serial.println("ASCII Table ~ Character Map"); 
 
25
 
26
 
 
27
// first visible ASCIIcharacter '!' is number 33:
 
28
int thisByte = 33; 
 
29
// you can also write ASCII characters in single quotes.
 
30
// for example. '!' is the same as 33, so you could also use this:
 
31
//int thisByte = '!';  
 
32
 
 
33
void loop() 
 
34
 
35
  // prints value unaltered, i.e. the raw binary version of the 
 
36
  // byte. The serial monitor interprets all bytes as 
 
37
  // ASCII, so 33, the first number,  will show up as '!' 
 
38
  Serial.print(thisByte, BYTE);    
 
39
 
 
40
  Serial.print(", dec: "); 
 
41
  // prints value as string as an ASCII-encoded decimal (base 10).
 
42
  // Decimal is the  default format for Serial.print() and Serial.println(),
 
43
  // so no modifier is needed:
 
44
  Serial.print(thisByte);      
 
45
  // But you can declare the modifier for decimal if you want to.
 
46
  //this also works if you uncomment it:
 
47
 
 
48
  // Serial.print(thisByte, DEC);  
 
49
 
 
50
 
 
51
  Serial.print(", hex: "); 
 
52
  // prints value as string in hexadecimal (base 16):
 
53
  Serial.print(thisByte, HEX);     
 
54
 
 
55
  Serial.print(", oct: "); 
 
56
  // prints value as string in octal (base 8);
 
57
  Serial.print(thisByte, OCT);     
 
58
 
 
59
  Serial.print(", bin: "); 
 
60
  // prints value as string in binary (base 2) 
 
61
  // also prints ending line break:
 
62
  Serial.println(thisByte, BIN);   
 
63
 
 
64
  // if printed last visible character '~' or 126, stop: 
 
65
  if(thisByte == 126) {     // you could also use if (thisByte == '~') {
 
66
    // This loop loops forever and does nothing
 
67
    while(true) { 
 
68
      continue; 
 
69
    } 
 
70
  } 
 
71
  // go on to the next character
 
72
  thisByte++;  
 
73