#include <IRremote.hpp>
#define IR_RECEIVE_PIN 2
#define IR_SEND_PIN 3
uint32_t lastCode = 0;
void setup() {
Serial.begin(9600);
delay(500);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK);
Serial.println("IR Clone Test Ready");
Serial.println("Press remote button to capture.");
Serial.println("Type 's' and press ENTER to send captured code.");
}
void loop() {
// ---- RECEIVE ----
if (IrReceiver.decode()) {
lastCode = IrReceiver.decodedIRData.decodedRawData;
Serial.print("Captured Code: 0x");
Serial.println(lastCode, HEX);
IrReceiver.resume();
}
// ---- SEND ----
if (Serial.available()) {
char cmd = Serial.read();
if (cmd == 's' || cmd == 'S') {
if (lastCode != 0) {
Serial.println("Sending captured IR code...");
IrSender.sendNECRaw(lastCode);
Serial.println("Signal complete");
} else {
Serial.println("No IR code captured yet.");
}
}
}
}