#include <IRremote.hpp>
#define IR_RECEIVE_PIN 2
struct Command {
IRRawDataType code; // numeric IR code
const char* command; // command name
};
Command commandList[] = {
{0x5DA2FF00, "power"},
};
const int commandCount = sizeof(commandList) / sizeof(commandList[0]);
byte redPin = 12;
byte greenPin = 9;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
Serial.begin(115200);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
}
void loop() {
if (IrReceiver.decode()) {
IRRawDataType outcome = IrReceiver.decodedIRData.decodedRawData;
// Look up in table
const char* cmd = "unknown";
for (int i = 0; i < commandCount; i++) {
if ( outcome == commandList[i].code) {
cmd = commandList[i].command;
break;
}
}
Serial.println(cmd);
IrReceiver.resume();
switch(cmd) {
case 'power': {
digitalWrite(greenPin, LOW);
digitalWrite(redPin, HIGH);
}
}
}
}