HI everyone,
I am working with P2P sample from your website and has done some modification.
I want to read incoming msg everytime so in whlie loop i have used " LORA_Read(msg); "
so it can read for msg ,if any, for each count. but there is some delay after each count++.
so i am looking for how to reduce delay OR is there any other option to run while loop and LORA_Read(msg); both at same time? if any please do tell. it is also welcomed if you have alternate coding for these program.
Here is my code:
#include <Keyboard.h>
#include <Arduino.h>
#include “LORA_P2P_lib.h”
#define CONSOLE_STREAM SerialUSB
#define LORA_STREAM Serial1
bool LED_Flag = 1;
volatile bool send_Flag = 0;
void setup()
{
pinMode(LED_GREEN, OUTPUT);
digitalWrite(LED_GREEN, HIGH);
pinMode(LED_BLUE, OUTPUT);
digitalWrite(LED_BLUE, HIGH);
digitalWrite(2,HIGH);
LORA_STREAM.begin(57600);
CONSOLE_STREAM.begin(57600);
delay(3000);
CONSOLE_STREAM.println(“Started!”);
LoraP2P_Setup();
CONSOLE_STREAM.println(“LORA SETUP DONE!”);
attachInterrupt(2, BTN_ISR, FALLING);
}
void BTN_ISR() {
send_Flag = 1;
CONSOLE_STREAM.println(“Interrupt!”);
}
void loop()
{
CONSOLE_STREAM.print("Input Pin state is: ");
CONSOLE_STREAM.println(digitalRead(2));
if (send_Flag == 1) {
send_Flag = 0;
CONSOLE_STREAM.println("Sending Message...");
LORA_Write("10");
delay(1000);
}
else {
char msg[100] = "";
CONSOLE_STREAM.println("Listening for Message...");
int errorCode = LORA_Read(msg); // We have a message if returncode = 1
if (errorCode == 1 && msg[0] == '1' && msg[1] == '0') { // Switch LED if message = 10
volatile int count = 0;
while (count < 10) {
digitalWrite(LED_GREEN, LOW); // Turn on pin 2 if there is a message
delay(1000);
digitalWrite(LED_GREEN, HIGH);
delay(30);
digitalWrite(LED_BLUE, LOW);
delay(1000);
digitalWrite(LED_BLUE, HIGH);
CONSOLE_STREAM.println(count);
count++;
char msg[100] = "/0";
LORA_Read(msg); // We have a message if returncode = 1
if (errorCode == 1 && msg[0] == ‘1’ && msg[1] == ‘0’)
{count = 0;
}
}
}
else {
CONSOLE_STREAM.println("Error: ");
CONSOLE_STREAM.println(errorCode);
}
}
}