How to Hold Raw IR Code and How to Send Raw IR Code in the same Program IRLib2

Hello! I'm unable to find a way to send and receive raw IR code in the same program. I want to send a signal from another IR remote to my IR receiver then when pressing a button send back that IR signal using an IR transmitter to e.g. a tv. Then, if I send another code, forget the previous one, and repeat the above.

Here's the IR receive example code:

/* rawR&cv.ino Example sketch for IRLib2
 *  Illustrate how to capture raw timing values for an unknow protocol.
 *  You will capture a signal using this sketch. It will output data the 
 *  serial monitor that you can cut and paste into the "rawSend.ino"
 *  sketch.
 */
// Recommend only use IRLibRecvPCI or IRLibRecvLoop for best results
#include <IRLibRecvPCI.h> 

IRrecvPCI myReceiver(2);//pin number for the receiver

void setup() {
  Serial.begin(9600);
  delay(2000); while (!Serial); //delay for Leonardo
  myReceiver.enableIRIn(); // Start the receiver
  Serial.println(F("Ready to receive IR signals"));
}

void loop() {
  //Continue looping until you get a complete signal received
  if (myReceiver.getResults()) { 
    Serial.println(F("Do a cut-and-paste of the following lines into the "));
    Serial.println(F("designated location in rawSend.ino"));
    Serial.print(F("\n#define RAW_DATA_LEN "));
    Serial.println(recvGlobal.recvLength,DEC);
    Serial.print(F("uint16_t rawData[RAW_DATA_LEN]={\n\t"));
    for(bufIndex_t i=1;i<recvGlobal.recvLength;i++) {
      Serial.print(recvGlobal.recvBuffer[i],DEC);
      Serial.print(F(", "));
      if( (i % 8)==0) Serial.print(F("\n\t"));
    }
    Serial.println(F("1000};"));//Add arbitrary trailing space
    myReceiver.enableIRIn();      //Restart receiver
  }
}

And here's the IR send example code:

/* rawSend.ino Example sketch for IRLib2
 *  Illustrates how to send a code Using raw timings which were captured
 *  from the "rawRecv.ino" sample sketch.  Load that sketch and
 *  capture the values. They will print in the serial monitor. Then you
 *  cut and paste that output into the appropriate section below.
 */
#include <IRLibSendBase.h>    //We need the base code
#include <IRLib_HashRaw.h>    //Only use raw sender

IRsendRaw mySender;

void setup() {
  Serial.begin(9600);
  delay(2000); while (!Serial); //delay for Leonardo
  Serial.println(F("Every time you press a key is a serial monitor we will send."));
}
/* Cut and paste the output from "rawRecv.ino" below here. It will 
 * consist of a #define RAW_DATA_LEN statement and an array definition
 * beginning with "uint16_t rawData[RAW_DATA_LEN]= {…" and concludes
 * with "…,1000};"
 */





/*
 * Cut-and-paste into the area above.
 */
   
void loop() {
  if (Serial.read() != -1) {
    //send a code every time a character is received from the 
    // serial port. You could modify this sketch to send when you
    // push a button connected to an digital input pin.
    mySender.send(rawData,RAW_DATA_LEN,36);//Pass the buffer,length, optionally frequency
    Serial.println(F("Sent signal."));
  }
}

I want to somehow join these separate programs together, eliminate the need for the Serial Monitor, and everything I stated already above. If you need more information, please, please, please, ask. Thank you in advance!

P.S. I'm sure you already noticed this, but I'm using the IRLib2 library. Most tutorials use the IRRemote library but all of them use the 2x version not the 3x, which is why I've decided to us this library.

  1. Put all your headers from RX and TX sketches together.
  2. Combine your void setup() procedures, without duplicating (for example, delay(2000);).
  3. Create two functions, one for RX one for TX.
  4. Inside void loop(), call RX() and TX() as needed.
  5. Hope there is no contention for who-is-sending-to-whom.
#include <IRLibSendBase.h>    //We need the base code
#include <IRLib_HashRaw.h>    //Only use raw sender
#include <IRLibRecvPCI.h> 

IRsendRaw mySender;           // does this guy need  pin?
IRrecvPCI myReceiver(2);      //pin number for the receiver

void loop ()
{
  Rx(parm1, parm2, parmN);
  Tx(parmA, parmB, parmN);
}

int Rx (int rx1, int rx2, int rxN)
{
  do (1);
}

int Tx (int tx1, int tx2, int txN)
{
  do (1);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.