-
Hello, I have a stupid problem that I can not solve. Ι use new example PingPong. The example work great with delay, but for my work i want millis(). With millis cant make startTrasmit again. What a mistake I have made? Thanks . #include<RadioLib.h>
SX1262 radio = new Module(10, 2, 3, 9);
int transmissionState = ERR_NONE;
bool transmitFlag = false;
volatile bool enableInterrupt = true;
volatile bool operationDone = false;
unsigned long SendTime = 1000;
unsigned long PreviousSend = 0;
void setFlag(void) {
if(!enableInterrupt) {
return;
}
operationDone = true;
}
void setup() {
Serial.begin(9600);
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
radio.setDio1Action(setFlag);
transmissionState = radio.startTransmit("Hello World!");
transmitFlag = true;
}
void loop() {
unsigned long currentMillis = millis();
if(operationDone) {
enableInterrupt = false;
operationDone = false;
if(transmitFlag) {
if (transmissionState == ERR_NONE) {
Serial.println(F("transmission finished!"));
} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);
}
radio.startReceive();
transmitFlag = false;
} else {
String str;
int state = radio.readData(str);
if (state == ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1262] Received packet!"));
// print data of the packet
Serial.print(F("[SX1262] Data:\t\t"));
Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
Serial.print(F("[SX1262] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print SNR (Signal-to-Noise Ratio)
Serial.print(F("[SX1262] SNR:\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
}
if(currentMillis - PreviousSend > SendTime)
{
PreviousSend = currentMillis;
transmissionState = radio.startTransmit("Hello World!");
transmitFlag = true;
}
}
enableInterrupt = true;
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
jgromes
Jul 29, 2021
Replies: 1 comment 3 replies
-
Probably because you have placed the if() condition that checks the timing value inside the if(operationDone) block. Therefore, you will only check the timer value when you get an interrupt. Try placing it in the loop() block. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
sexton10
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably because you have placed the if() condition that checks the timing value inside the if(operationDone) block. Therefore, you will only check the timer value when you get an interrupt.
Try placing it in the loop() block.