1 | #include <IRremote.h>
|
2 |
|
3 | int RECV_PIN = 11;
|
4 |
|
5 | IRrecv irrecv(RECV_PIN);
|
6 |
|
7 | decode_results results;
|
8 |
|
9 | void setup()
|
10 | {
|
11 | Serial.begin(9600);
|
12 | irrecv.enableIRIn(); // Start the receiver
|
13 | }
|
14 |
|
15 | // Dumps out the decode_results structure.
|
16 | // Call this after IRrecv::decode()
|
17 | // void * to work around compiler issue
|
18 | //void dump(void *v) {
|
19 | // decode_results *results = (decode_results *)v
|
20 | void dump(decode_results *results) {
|
21 | int count = results->rawlen;
|
22 | if (results->decode_type == UNKNOWN) {
|
23 | Serial.print("Unknown encoding: ");
|
24 | }
|
25 | else if (results->decode_type == NEC) {
|
26 | Serial.print("Decoded NEC: ");
|
27 | }
|
28 | else if (results->decode_type == SONY) {
|
29 | Serial.print("Decoded SONY: ");
|
30 | }
|
31 | else if (results->decode_type == RC5) {
|
32 | Serial.print("Decoded RC5: ");
|
33 | }
|
34 | else if (results->decode_type == RC6) {
|
35 | Serial.print("Decoded RC6: ");
|
36 | }
|
37 | else if (results->decode_type == PANASONIC) {
|
38 | Serial.print("Decoded PANASONIC - Address: ");
|
39 | Serial.print(results->panasonicAddress,HEX);
|
40 | Serial.print(" Value: ");
|
41 | }
|
42 | else if (results->decode_type == JVC) {
|
43 | Serial.print("Decoded JVC: ");
|
44 | }
|
45 | Serial.print(results->value, HEX);
|
46 | Serial.print(" (");
|
47 | Serial.print(results->bits, DEC);
|
48 | Serial.println(" bits)");
|
49 | Serial.print("Raw (");
|
50 | Serial.print(count, DEC);
|
51 | Serial.print("): ");
|
52 |
|
53 | for (int i = 0; i < count; i++) {
|
54 | if ((i % 2) == 1) {
|
55 | Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
|
56 | }
|
57 | else {
|
58 | Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
|
59 | }
|
60 | Serial.print(" ");
|
61 | }
|
62 | Serial.println("");
|
63 | }
|
64 |
|
65 |
|
66 | void loop() {
|
67 | if (irrecv.decode(&results)) {
|
68 | Serial.println(results.value, HEX);
|
69 | dump(&results);
|
70 | irrecv.resume(); // Receive the next value
|
71 | }
|
72 | }
|