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.