Skip to content

Commit d0ee208

Browse files
committed
Create LoRaSenderNonBlockingCallback.ino
Simple Example non-blocking callback
1 parent e641518 commit d0ee208

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <SPI.h>
2+
#include <LoRa.h>
3+
4+
int counter = 0;
5+
6+
void setup() {
7+
Serial.begin(9600);
8+
while (!Serial);
9+
10+
Serial.println("LoRa Sender non-blocking Callback");
11+
12+
if (!LoRa.begin(915E6)) {
13+
Serial.println("Starting LoRa failed!");
14+
while (1);
15+
}
16+
17+
LoRa.onTxDone(onTxDone);
18+
}
19+
20+
void loop() {
21+
if (runEvery(1000)) { // repeat every 1000 millis
22+
23+
Serial.print("Sending packet non-blocking: ");
24+
Serial.println(counter);
25+
26+
// send in async / non-blocking mode
27+
LoRa.beginPacket();
28+
LoRa.print("hello ");
29+
LoRa.print(counter);
30+
LoRa.endPacket(true); // true = async / non-blocking mode
31+
32+
counter++;
33+
}
34+
}
35+
36+
void onTxDone() {
37+
Serial.println("TxDone");
38+
}
39+
40+
boolean runEvery(unsigned long interval)
41+
{
42+
static unsigned long previousMillis = 0;
43+
unsigned long currentMillis = millis();
44+
if (currentMillis - previousMillis >= interval)
45+
{
46+
previousMillis = currentMillis;
47+
return true;
48+
}
49+
return false;
50+
}

0 commit comments

Comments
 (0)