|
1 | | -#define sprint Serial.print |
| 1 | +#define sprint Serial.print |
2 | 2 | #define sprintln Serial.println |
3 | | -#include <IRremote.h> |
| 3 | +#include <IRremote.hpp> // IRremote 4.1.2 from Library Manager |
4 | 4 | int RECV_PIN = 11; |
5 | 5 |
|
6 | | - |
7 | | -IRrecv irrecv(RECV_PIN); |
8 | | - |
9 | | - |
10 | | -decode_results results; |
| 6 | +unsigned long timeBegin; |
11 | 7 | int c = 1; |
12 | | - unsigned long timeBegin; |
| 8 | + |
13 | 9 | void setup() |
14 | 10 | { |
15 | 11 | Serial.begin(9600); |
16 | | - irrecv.enableIRIn(); // Start the receiver |
| 12 | + IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK); // Start the receiver |
17 | 13 | timeBegin = micros(); |
18 | | - |
19 | 14 | } |
20 | 15 |
|
21 | 16 | void loop() { |
22 | | - |
23 | | - |
24 | | - if (irrecv.decode(&results)) { |
25 | | - dump(&results); |
| 17 | + if (IrReceiver.decode()) { |
| 18 | + dump(); |
26 | 19 | // ======== |
27 | | - Serial.println(results.value, HEX); |
| 20 | + Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); |
28 | 21 | Serial.print("rawlen "); |
29 | | - Serial.println(results.rawlen); |
| 22 | + Serial.println(IrReceiver.decodedIRData.rawDataPtr->rawlen); |
30 | 23 | Serial.print("decode type "); |
31 | | - Serial.println(results.decode_type); |
| 24 | + Serial.println(IrReceiver.decodedIRData.protocol); |
32 | 25 |
|
33 | 26 | unsigned long timeEnd = micros(); |
34 | 27 | unsigned long duration = timeEnd - timeBegin; |
35 | 28 | double averageDuration = (double)duration / 1000.0; |
36 | 29 | Serial.println(averageDuration); |
37 | | -// if(results.value==0xA1026EFF) { |
| 30 | +// if(IrReceiver.decodedIRData.decodedRawData==0xA1026EFF) { |
38 | 31 | // Serial.println("turning off"); |
39 | 32 | // } |
40 | | - irrecv.resume(); // Receive the next value |
41 | | - |
| 33 | + IrReceiver.resume(); // Receive the next value |
42 | 34 | } |
43 | 35 | } |
44 | 36 |
|
45 | | -void dump(decode_results *results) { |
46 | | - int count = results->rawlen; |
| 37 | +void dump() { |
| 38 | + int count = IrReceiver.decodedIRData.rawDataPtr->rawlen; |
47 | 39 | sprintln(c); |
48 | 40 | c++; |
49 | 41 | sprintln("For IR Scope: "); |
50 | 42 | for (int i = 1; i < count; i++) { |
51 | 43 | sprint("0x"); |
52 | | - sprint((unsigned int)results->rawbuf[i], HEX); |
| 44 | + sprint((unsigned int)IrReceiver.decodedIRData.rawDataPtr->rawbuf[i] * MICROS_PER_TICK, HEX); |
53 | 45 | sprint(" "); |
54 | 46 | } |
55 | 47 |
|
56 | 48 | sprintln(""); |
57 | 49 | sprintln("For Arduino sketch: "); |
58 | | - sprint("unsigned int raw["); |
| 50 | + sprint("uint16_t raw["); |
59 | 51 | sprint(count, DEC); |
60 | 52 | sprint("] = {"); |
61 | 53 | for (int i = 1; i < count; i++) { |
62 | 54 | sprint("0x"); |
63 | | - sprint((unsigned int)results->rawbuf[i], HEX); |
| 55 | + sprint((unsigned int)IrReceiver.decodedIRData.rawDataPtr->rawbuf[i] * MICROS_PER_TICK, HEX); |
64 | 56 | sprint(","); |
65 | 57 | } |
66 | 58 | sprint("};"); |
67 | 59 | sprintln(""); |
68 | | - sprint("irsend.sendRaw(raw,"); |
| 60 | + sprint("IrSender.sendRaw(raw,"); |
69 | 61 | sprint(count, DEC); |
70 | 62 | sprint(",38);"); |
71 | 63 | sprintln(""); |
|
0 commit comments