#include <Wire.h>
#include "rgb_lcd.h"
#include <SPI.h>
#include <LoRa.h>
int counter = 0;
rgb_lcd lcd;
const int colorR = 255;
const int colorG = 20;
const int colorB = 147;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
// lcd.display();
// Print a message to the LCD.
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Sender");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
lcd.print("LoRa Initialised");
Serial.println("LoRa Initialised");
LoRa.setTxPower(20);
LoRa.setSpreadingFactor(12);
LoRa.setSignalBandwidth(62.5E3);
LoRa.setCodingRate4(8);
delay(1000);
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
lcd.setCursor(0, 0);
lcd.print("Received packet ");
// read packet
int count = 0;
while (LoRa.available()) {
lcd.setCursor(count, 0);
count++;
// do not print to serial and lcd at same time as once read a character is removed from the stream
// Serial.print((char)LoRa.read());
lcd.print((char)LoRa.read());
}
lcd.setCursor(0, 1);
lcd.print(LoRa.packetRssi());
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
delay(2000);
} else {
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("Listening... ");
}
}