mirror of
https://github.com/sandeepmistry/arduino-LoRa.git
synced 2025-04-19 13:02:14 +03:00
Create LoRaSenderNonBlockingCallback.ino
Simple Example non-blocking callback
This commit is contained in:
parent
e641518510
commit
d0ee20860f
@ -0,0 +1,50 @@
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
|
||||
int counter = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("LoRa Sender non-blocking Callback");
|
||||
|
||||
if (!LoRa.begin(915E6)) {
|
||||
Serial.println("Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
|
||||
LoRa.onTxDone(onTxDone);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (runEvery(1000)) { // repeat every 1000 millis
|
||||
|
||||
Serial.print("Sending packet non-blocking: ");
|
||||
Serial.println(counter);
|
||||
|
||||
// send in async / non-blocking mode
|
||||
LoRa.beginPacket();
|
||||
LoRa.print("hello ");
|
||||
LoRa.print(counter);
|
||||
LoRa.endPacket(true); // true = async / non-blocking mode
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
void onTxDone() {
|
||||
Serial.println("TxDone");
|
||||
}
|
||||
|
||||
boolean runEvery(unsigned long interval)
|
||||
{
|
||||
static unsigned long previousMillis = 0;
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= interval)
|
||||
{
|
||||
previousMillis = currentMillis;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user