]> git.piffa.net Git - arduino/blob - books/pdummies/Libraries/IRremote/examples/IRrecvDump/IRrecvDump.ino
first commit
[arduino] / books / pdummies / Libraries / IRremote / examples / IRrecvDump / IRrecvDump.ino
1 /*
2  * IRremote: IRrecvDump - dump details of IR codes with IRrecv
3  * An IR detector/demodulator must be connected to the input RECV_PIN.
4  * Version 0.1 July, 2009
5  * Copyright 2009 Ken Shirriff
6  * http://arcfn.com
7  * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
8  */
9
10 #include <IRremote.h>
11
12 int RECV_PIN = 11;
13
14 IRrecv irrecv(RECV_PIN);
15
16 decode_results results;
17
18 void setup()
19 {
20   Serial.begin(9600);
21   irrecv.enableIRIn(); // Start the receiver
22 }
23
24 // Dumps out the decode_results structure.
25 // Call this after IRrecv::decode()
26 // void * to work around compiler issue
27 //void dump(void *v) {
28 //  decode_results *results = (decode_results *)v
29 void dump(decode_results *results) {
30   int count = results->rawlen;
31   if (results->decode_type == UNKNOWN) {
32     Serial.print("Unknown encoding: ");
33   } 
34   else if (results->decode_type == NEC) {
35     Serial.print("Decoded NEC: ");
36   } 
37   else if (results->decode_type == SONY) {
38     Serial.print("Decoded SONY: ");
39   } 
40   else if (results->decode_type == RC5) {
41     Serial.print("Decoded RC5: ");
42   } 
43   else if (results->decode_type == RC6) {
44     Serial.print("Decoded RC6: ");
45   }
46   else if (results->decode_type == PANASONIC) { 
47     Serial.print("Decoded PANASONIC - Address: ");
48     Serial.print(results->panasonicAddress,HEX);
49     Serial.print(" Value: ");
50   }
51   else if (results->decode_type == JVC) {
52      Serial.print("Decoded JVC: ");
53   }
54   Serial.print(results->value, HEX);
55   Serial.print(" (");
56   Serial.print(results->bits, DEC);
57   Serial.println(" bits)");
58   Serial.print("Raw (");
59   Serial.print(count, DEC);
60   Serial.print("): ");
61
62   for (int i = 0; i < count; i++) {
63     if ((i % 2) == 1) {
64       Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
65     } 
66     else {
67       Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
68     }
69     Serial.print(" ");
70   }
71   Serial.println("");
72 }
73
74
75 void loop() {
76   if (irrecv.decode(&results)) {
77     Serial.println(results.value, HEX);
78     dump(&results);
79     irrecv.resume(); // Receive the next value
80   }
81 }