/* *******************************************
the current July sketch 31.07.19
*/
int FIRMWARE = 731;// 31 july 2019 WORKING OK
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
int message; // this it capture message from tx
int newMessage;
int lastmessage;
int prevmessage;
int capt ;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
int btnPin = A0;
int LedPin = 4;
int FetPin = 3;
void setup() {
Serial.begin(9600);
pinMode (btnPin,INPUT);
pinMode (LedPin,OUTPUT);
pinMode (FetPin,OUTPUT);
digitalWrite (LedPin, LOW);
while (!Serial);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.cp437(true); // Use full 256 char 'Code Page 437' font
delay(100);
// Clear the buffer
display.clearDisplay();
// Draw a single pixel in white
display.drawPixel(10, 10, WHITE);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(10);
// display.display() is NOT necessary after every single drawing command,
// unless that's what you want...rather, you can batch up a bunch of
// drawing operations and then update the screen all at once by calling
// display.display(). These examples demonstrate both approaches...
// Invert and restore display, pausing in-between
// display.invertDisplay(true);
// delay(1000);
// display.invertDisplay(false);
// delay(1000);
// testanimate(logo_bmp, LOGO_WIDTH, LOGO_HEIGHT); // Animate bitmaps
Serial.println("LoRa Receiver");
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.cp437(true); // Use full 256 char 'Code Page 437' font
//ALARM TESTING
delay(100); // Pause for 1 seconds
display.print (" FIRMWARE No ");
display.println (FIRMWARE);
display.display();
delay(1000);
display.print (" LED TEST ");
display.display();
digitalWrite (LedPin,LOW);
delay (2000);
display.clearDisplay();
delay(500);
display.print ("SIREN TEST ");
display.display();
digitalWrite (FetPin,HIGH);
delay(3000);
digitalWrite (FetPin,LOW);
digitalWrite (LedPin,HIGH);
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.cp437(true); // Use full 256 char 'Code Page 437' font
display.println (" Listening");
display.display();
delay(500);
if (!LoRa.begin(923E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
digitalWrite (LedPin,HIGH);
delay(10);
digitalWrite (FetPin,LOW);
delay(10);
display.setCursor(0,00);
display.setTextColor(WHITE);
display.setTextSize(2);
// try to parse packet
display.clearDisplay();
delay(10);
int packetSize = LoRa.parsePacket();
if (packetSize) {
// read packet
while (LoRa.available()) {
newMessage =((char)LoRa.read());
// Serial.print(message);
capt = newMessage;
Serial.print("capt =");
Serial.print(capt);
digitalWrite (LedPin,LOW);
digitalWrite (FetPin,HIGH);
delay (10);
//changes it here reading the char of lora
// message =((char)LoRa.read());
delay(5);
display.print ((char)newMessage);
display.display();
delay(5);
message = newMessage;
if (newMessage >0){getlastmessage();}
newMessage = 0;
delay(5);
}
// print RSSI of packet
display.setCursor(0,55);// starts bottom left
display.setTextSize(1);
display.print(" SIGNAL ");
display.print(LoRa.packetRssi());
display.print(" db ");
display.display();
// delay(10);
display.clearDisplay();
delay(10);
// display.invertDisplay(true);
// delay(1000);
// display.invertDisplay(false);
delay(10);
}
}
void testdrawbitmap(void) {
display.clearDisplay();
display.drawBitmap(
(display.width() - LOGO_WIDTH ) / 2,
(display.height() - LOGO_HEIGHT) / 2,
logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
display.display();
delay(5000);
}
void getlastmessage () {
prevmessage = message;
delay(5);
lastmessage = prevmessage ;
delay(5);
//Serial.print("prevmessage ");
// Serial.print((char)prevmessage);
//Serial.println("");
// delay(5);
Serial.print(" lastmessage ");
Serial.print((char)lastmessage);
Serial.println("");
delay(5);
//Serial.print("message ");
//Serial.print((char)message);
//Serial.println("");
//delay(5);
}