LilyGo-LoRa-Series/examples/ArduinoLoRa/LoRaSender/LoRaSender.ino

43 lines
884 B
Arduino
Raw Normal View History

2020-11-24 17:03:49 +08:00
#include <LoRa.h>
#include "boards.h"
2020-11-24 17:03:49 +08:00
int counter = 0;
void setup()
{
initBoard();
// When the power is turned on, a delay is required.
delay(1500);
Serial.println("LoRa Sender");
LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DI0_PIN);
if (!LoRa.begin(LoRa_frequency)) {
2020-11-24 17:03:49 +08:00
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop()
{
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
#ifdef HAS_DISPLAY
if (u8g2) {
char buf[256];
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Transmitting: OK!");
snprintf(buf, sizeof(buf), "Sending: %d", counter);
u8g2->drawStr(0, 30, buf);
u8g2->sendBuffer();
}
#endif
2020-11-24 17:03:49 +08:00
counter++;
delay(5000);
}