1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include "SSD1306.h"
//#include "images.h"
#define SCK 5 // GPIO5 -- SX1278's SCK
#define MISO 19 // GPIO19 -- SX1278's MISO
#define MOSI 27 // GPIO27 -- SX1278's MOSI
#define SS 18 // GPIO18 -- SX1278's CS
#define RST 14 // GPIO14 -- SX1278's RESET
#define DI0 26 // GPIO26 -- SX1278's IRQ(Interrupt Request)
#define BAND 433E6
unsigned int counter = 0;
const int SW1 = 32;
const int SW2 = 33;
int SyncWord = 0x22;
int pValue1 = 1;
int pValue2 = 1;
int lValue1 = 0;
int lValue2 = 0;
bool Flag1 = false;
bool Flag2 = false;
int data = 1;
SSD1306 display(0x3c, 4, 15);
String rssi = "RSSI --";
String packSize = "--";
String packet ;
/*
void logo(){
display.clear();
display.drawXbm(0,5,logo_width,logo_height,logo_bits);
display.display();
}
*/
void setup() {
pinMode(16,OUTPUT);
pinMode(2,OUTPUT);
pinMode(SW1,INPUT_PULLUP);
pinMode(SW2,INPUT_PULLUP);
digitalWrite(16, LOW); // set GPIO16 low to reset OLED
delay(50);
digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high
Serial.begin(9600);
while (!Serial);
Serial.println();
Serial.println("LoRa Sender Test");
SPI.begin(SCK,MISO,MOSI,SS);
LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setSpreadingFactor(12); // ranges from 6-12,default 7 see API docs
LoRa.setSignalBandwidth(62.5E3 ); // for -139dB (page - 112)
LoRa.setCodingRate4(8); // for -139dB (page - 112)
LoRa.setSyncWord(SyncWord);
//LoRa.onReceive(cbk);
// LoRa.receive();
Serial.println("init ok");
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
//logo();
delay(50);
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
}
void loop() {
display.clear();
/*
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
*/
lValue1 = digitalRead(SW1);
lValue2 = digitalRead(SW2);
/*
display.drawString(0, 0, "Sending packet: ");
display.drawString(90, 0, String(counter));
display.display();
*/
if( (lValue1 == 0) and (Flag1 == false) )
{
delay(50);
data = 11;
Serial.println("11");
Flag1 = true;
pValue1 = !pValue1;
LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();
}
if( (lValue1 == 1) and (Flag1 == true) )
{
delay(50);
data = 22;
Serial.println("22");
Flag1 = false;
LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();
}
if( (lValue2 == 0) and (Flag2 == false))
{
delay(50);
data = 33;
Serial.println("33");
Flag2 = true;
pValue2 = !pValue2;
LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();
}
if( (lValue2 == 1) and (Flag2 == true) )
{
delay(50);
data = 44;
Serial.println("44");
Flag2 = false;
LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();
}
if( (lValue1 == 1) and (lValue2 == 1) )
{
data = 55;
Serial.println("55");
LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();
}
/*
counter++;
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a 1/2 second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a 1/2 second
*/
} |
Partager