#include <IRremote.h> // do not create an IRremote object
const int RECV_PIN = 2;
const int LED_PIN = 10;
bool ledState = LOW;
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK); // initialize IRremote object
Serial.println("IR Receiver Ready. Press a button on remote.");
}
void loop() {
if (IrReceiver.decode()) {
long protocol = IrReceiver.decodedIRData.protocol;
long rawData = IrReceiver.decodedIRData.decodedRawData;
printProtocol(protocol);
printRawData(rawData);
switch (rawData) {
case 0x5DA2FF00: // POWER button
toggleLED();
break;
default: break;
}
IrReceiver.resume(); // restart decoding
Serial.println();
}
}
void toggleLED() {
ledState = !ledState;
Serial.print(" LED toggled to ");
Serial.print(ledState ? "HIGH" : "LOW");
digitalWrite(LED_PIN, ledState ? HIGH : LOW); // toggle LED
}
void printProtocol(long prot) {
Serial.print("Protocol: ");
if (prot < 10)
Serial.print(" ");
Serial.print(prot);
}
void printRawData(long data) {
Serial.print(" HEX value: ");
Serial.print(data, HEX);
}