-
Notifications
You must be signed in to change notification settings - Fork 0
/
IRremoteDecode.ino
50 lines (38 loc) · 1.41 KB
/
IRremoteDecode.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// This sketch uses the IRrevc class of IRremote (can be installed from Arduino
// library manager). It reads IR signals with that class, and sends it
// to DecodeIR.
// Of course, the library IRremote needs be installed to compile
// and run this sketch.
// Due to the shortcomings of the IRremote library, the decodes that
// come out are not always really sensible.
// This sketch uses the IRremote library because it is widely spread and known.
// Please try my library Infrared (Infrared4Arduino) too (or instead).
// It has some advantages...
// Requires around 109236 bytes of program storage space, and 2538 of RAM.
// Differently put, will not run on anything considerably smaller than
// Mega 2560.
#include <IRremote.h>
#include <decodePrintIr.h>
static const unsigned int RECV_PIN = 47;//11;
static IRrecv irrecv(RECV_PIN);
static decode_results results;
void decode(decode_results* results) {
//Serial.println(results->value, HEX);
unsigned int length = results->rawlen;
microseconds_t buf[length];
for (unsigned int i = 0; i < length - 1; i++) {
buf[i] = USECPERTICK*results->rawbuf[i+1];
}
buf[length-1] = 65000U;
decodePrintIr(Serial, buf, length/2);
}
void setup() {
Serial.begin(115200);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
decode(&results);
irrecv.resume(); // Receive the next value
}
}