I am trying to merge "include <LoRa.h>" and "include <IRremote.h>" so that I can use a remote control
to send specific information via Lora.
Seperately, both Sketches function exactly as expected , however when I merge them together the
merged sketch works fine until it receives the signal from the remote then it displays the data once
and stalls.
#include <LoRa.h>
byte localAddress = 0xAA;
byte destinationAddress = 0xBB;
int staT = 0;
long lastSendTime = 0;
unsigned int interval = 3000;
int reC = 0;
//................IR REMOTE
#define DECODE_NEC 1
#include <IRremote.h>
int IR_RECEIVE_PIN = 9;
unsigned int keycode = 0;
void setup() {
Serial.begin(9600);
//... STARTING LORA ................
Serial.println("Start LoRa duplex TX Sender");
if (!LoRa.begin(915E6)) {
Serial.println("LoRa init failed. Check your connections.");
while (true) {}
}
//................IR REMOTE
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);
}
void senddatA()
{
if (millis() - lastSendTime > interval) {
String message = String(staT);
sendMessage(message);
Serial.println(" SENT " + message);
// Serial.print(" from 0x" + String(localAddress, HEX));
// Serial.println(" to 0x" + String(destinationAddress, HEX));
lastSendTime = millis();
}
}
//... VOID SEND MESSAGE .............................
void sendMessage(String outgoing) {
digitalWrite(3, HIGH);
LoRa.beginPacket();
LoRa.write(destinationAddress);
LoRa.write(localAddress);
LoRa.write(outgoing.length());
LoRa.print(outgoing);
LoRa.endPacket();
delay(500);
}
void receiveMessage(int packetSize) {
if (packetSize == 0) return;
int recipient = LoRa.read();
byte sender = LoRa.read();
byte incomingLength = LoRa.read();
String incoming = "";
while (LoRa.available()) {
incoming += (char)LoRa.read();
}
reC = incoming.toInt();
digitalWrite(6, HIGH); delay(500); digitalWrite(6, LOW);
Serial.print (" Received "); Serial.println (reC);
}
void irremotE() {
keycode = IrReceiver.decodedIRData.command;
if (keycode != 0) {
Serial.print(" INside Void IRRec "); Serial.println(keycode, HEX);
delay(1000);
Serial.print(" END of Void IRRec");
}
}
void loop() {
IrReceiver.resume();
staT = 220; senddatA();
receiveMessage(LoRa.parsePacket()); // RECEIVE MESSAGE
Serial.print (" START VOID LOOP ");Serial.println(keycode);
delay(1000);
if (IrReceiver.decode() != 0);
keycode = IrReceiver.decodedIRData.command;
Serial.print (" IN VOID LOOP after irDeCode ");Serial.println(keycode, HEX);
delay(1000);
irremotE();
This is the Screen Print of the outputs.