If you’re using Arduino 1.6.0,
IRremote
collides with one of the Arduino IDE’s
new standard libraries named
RobotIRremote
. In this case you have to delete
RobotIRremote
to make this chapter’s examples run. On a Mac you need to delete
/Applications/Arduino.app/Contents/Resources/Java/libraries/RobotIRremote/. On a Windows machine,
it's something like
C:\Program Files (x86)\Arduino\libraries\RobotIRremote‘.
With the following sketch, you can then decode incoming infrared signals, if
the IRremote library supports their encoding:
RemoteControl/InfraredDumper/InfraredDumper.ino
#include <IRremote.h>
Line 1
-
const unsigned int IR_RECEIVER_PIN = 11;
-
const unsigned int BAUD_RATE = 9600;
-
5
IRrecv ir_receiver(IR_RECEIVER_PIN);
-
decode_results results;
-
-
void setup() {
-
Serial.begin(BAUD_RATE);
10
ir_receiver.enableIRIn();
-
}
-
-
void dump(const decode_results* results) {
-
const int protocol = results->decode_type;
15
Serial.print("Protocol: ");
-
if (protocol == UNKNOWN) {
-
Serial.println("not recognized.");
-
} else if (protocol == NEC) {
-
Serial.println("NEC");
20
} else if (protocol == SONY) {
-
Serial.println("SONY");
-
} else if (protocol == RC5) {
-
Serial.println("RC5");
-
} else if (protocol == RC6) {
25
Serial.println("RC6");
-
} else if (protocol == DISH) {
-
Serial.println("DISH");
-
} else if (protocol == SHARP) {
-
Serial.println("SHARP");
30
} else if (protocol == PANASONIC) {
-
Serial.print("PANASONIC (");
-
Serial.print("Address: ");
-
Serial.print(results->panasonicAddress, HEX);
-
Serial.println(")");
35
} else if (protocol == JVC) {
-
Serial.println("JVC");
-
} else if (protocol == SANYO) {
-
Serial.println("SANYO");
-
} else if (protocol == MITSUBISHI) {
40
report erratum • discuss
Grabbing Remote Control Codes • 205
www.it-ebooks.info