File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
examples/LoRaSenderNonBlockingCallback Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments