/*both codes work, go back and pick which one is more efficient*/
#include <IRremote.h>
// IR receiver pin
//#define IR_RECEIVE 27 // receiver pin, adjust as needed
const uint16_t IR_RECEIVE = 27; // receiver pin, adjust as needed
IRrecv irrecv(IR_RECEIVE);
void setup() {
Serial.begin(115200);
irrecv.enableIRIn(); // starting IR receiver
Serial.println("Ready to receive IR signals...");
}
void loop() {
decode_results results; // varible to store the results of the IR decoding
if(irrecv.decode(&results)) { // if an IR signal is decoded
/*Serial.println("Received IR signal!"); // successfully able to decode the received IR signal
// printing out raw data for the received IR signal
Serial.print("Raw data: ");
for(int i =0; i < results.rawlen; i++) { // looping through all the intervals of the IR signal
Serial.print(results.rawbuf[i]*USECPERTICK, DEC); // printing each interval duration in microseconds
if(i+1 < results.rawlen) { // printing comma after each number
Serial.print(",");
}
}
Serial.println(); // newline character*/
/*new addition starts here*/
if(results.rawlen == 2) { // checking to see is the length of raw data is 2 (character)
char receivedChar = (char)results.rawbuf[0];
if(receivedChar != 0xFFFF) { // checking if it's not the end of a character marker
Serial.print(receivedChar);
}
}
/*new addition starts here*/
irrecv.resume(); // prepare for the next IR signal, clears the receiver's buffer and makes it ready to receive another signal
}
}
/*#include <IRremote.h>
// IR receiver pin
//#define IR_RECEIVE 27 // receiver pin, adjust as needed
const uint16_t IR_RECEIVE = 27; // receiver pin, adjust as needed
IRrecv irrecv(IR_RECEIVE);
void setup() {
Serial.begin(115200);
irrecv.enableIRIn(); // starting IR receiver
Serial.println("Ready to receive IR signals...");
}
void loop() {
if(irrecv.decode()) { // if an IR signal is decoded
Serial.println("Received IR signal!"); // reception of the signal
// printing the protocol of the received IR signal
Serial.print("Protocol: ");
Serial.println(irrecv.getProtocolString()); // converting the protocol to a string and printing it out
// printing the number of bits in the received IR signal
Serial.print("Bits: ");
Serial.println(irrecv.decodedIRData.numberOfBits); // number of bits received
// printing the value of the received IR signal in hex
Serial.print("Value: ");
Serial.println(irrecv.decodedIRData.decodedRawData, HEX); // raw data of the signal
irrecv.resume(); // prepare for the next IR signal, clears the receiver's buffer and makes it ready to receive another signal
}
}*/