#include const int led = LED_BUILTIN; // On board LED, Pin 13 const int RECV_PIN = 7; // IR Receiver String input = ""; bool done = false; IRsend sendr; // Make Send Object, DANGER a fixed pin number is always used! (3) //IRrecv recvr(RECV_PIN); // Make Recever Object decode_results results; // Make Results Object to store received codes void setup() { // Initalize on board LED pinMode(led, OUTPUT); digitalWrite(led, LOW); // Initalize input routine input.reserve(60); // Max input of chars, to merge into string done = false; // Initalize IR connections //recvr.enableIRIn(); //recvr.blink13(false); // Disabled Pin 13 blinking on IR signal received // Initalize Output routine Serial.begin(9600); // Serial COM's Port while(!Serial) { delay(10); } // Wait for conection Serial.println("Serial Connected!"); digitalWrite(LED_BUILTIN, LOW); } void sendCode(byte code, int bit_len, bool repeat) { // If repeat the code then repeat it 3 times if(repeat) { for(int x = 0; x <= 3; x++) { sendr.sendNEC(code, bit_len); delay(40); } } else { // Else send the code then repeat a blank 2 times sendr.sendNEC(code, bit_len); delay(40); for(int x = 0; x <= 2; x++) { sendr.sendNEC(0xFFFFFFFF, 32); delay(40); } } } void action(String act){ // Given String execute action if(act == "tv p"){ sendCode(0x57E3E817, 32, true); Serial.println("tv power"); } else if(act == "m p"){ sendCode(0x807F02FD, 32, false); Serial.println("movie power"); } } void loop() { // Are we sending/receiving data? if(Serial.available() > 0) { char in = (char)Serial.read(); if (in == '\n') { done = true; } else if (in == '\n') { done = true; } else { input += in; } } if(done){ action(input); // Execute command / handle command input = ""; done = false; } }