//#define DECODE_NEC // Includes Apple and Onkyo. To enable all protocols , just comment/disable this line. #define NEC_PROTOCOL 8 #define IR_RECEIVE_PIN 2 #define IR_TRANSMIT_PIN 3 #define LED 7 #include // include the library #define DELAY_AFTER_SEND 2000 #define DELAY_AFTER_LOOP 5000 bool switching = false; void setup() { Serial.begin(115200); IrSender.begin(IR_TRANSMIT_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); Serial.print(F("Ready to receive IR signals of protocols: ")); printActiveIRProtocols(&Serial); pinMode(LED, OUTPUT); } void loop() { if (switching) { Serial.println(F("Send NEC with 8 bit address")); Serial.flush(); IrSender.sendNEC(0x0, 0xC, 1); delay(DELAY_AFTER_SEND); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal switching = false; } else { Serial.println(F("Send NEC with 8 bit address")); Serial.flush(); IrSender.sendNEC(0x0, 0x18, 1); delay(DELAY_AFTER_SEND); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal switching = true; } /* * Decoded result is in the IrReceiver.decodedIRData structure. */ if (IrReceiver.decode()) { Serial.println("IN"); IrReceiver.resume(); // Early enable receiving of the next IR frame IrReceiver.printIRResultShort(&Serial); IrReceiver.printIRSendUsage(&Serial); Serial.println(); } if (IrReceiver.decodedIRData.command == 0xC) { digitalWrite(LED, HIGH); } else if (IrReceiver.decodedIRData.command == 0x18) { digitalWrite(LED, LOW); } delay(1000); }