Skip to content

Commit bcc6394

Browse files
Merge pull request #36 from Quency-D/master
lora control LED
2 parents a433e99 + 189d073 commit bcc6394

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Receive the lora signal to control the on and off of the LED.
3+
Pull the 12th pin high to turn on the LED light.
4+
Pull pin 13 high to turn off the LED light.
5+
by Aaron.Lee from HelTec AutoMation, ChengDu, China
6+
成都惠利特自动化科技有限公司
7+
www.heltec.cn
8+
9+
this project also realess in GitHub:
10+
https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series
11+
*/
12+
13+
#include "heltec.h"
14+
#include "string.h"
15+
#include "stdio.h"
16+
#define LED 25
17+
#define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6
18+
char Readback[50];
19+
void setup() {
20+
//WIFI Kit series V1 not support Vext control
21+
Heltec.begin(false /*DisplayEnable Enable*/, true /*Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
22+
pinMode(LED,OUTPUT);
23+
digitalWrite(LED,LOW);
24+
}
25+
26+
void loop() {
27+
// try to parse packet
28+
int packetSize = LoRa.parsePacket();
29+
if (packetSize) {
30+
// received a packet
31+
Serial.print("Received packet '");
32+
// read packet
33+
while (LoRa.available()) {
34+
sprintf(Readback+strlen(Readback),"%c",(char)LoRa.read());
35+
}
36+
Serial.print(Readback);
37+
if(strncmp(Readback, "OpenLED", strlen(Readback)) == 0) {
38+
digitalWrite(LED, HIGH);
39+
}
40+
else if(strncmp(Readback, "CloseLED", strlen(Readback)) == 0) {
41+
digitalWrite(LED, LOW);
42+
}
43+
memset(Readback,0,50);
44+
// print RSSI of packet
45+
Serial.print(" with RSSI ");
46+
Serial.println(LoRa.packetRssi());
47+
}
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Send a lora signal to control the LED light switch of another board.
3+
Pull the 12th pin high to turn on the LED light.
4+
Pull pin 13 high to turn off the LED light.
5+
by Aaron.Lee from HelTec AutoMation, ChengDu, China
6+
成都惠利特自动化科技有限公司
7+
www.heltec.cn
8+
9+
this project also realess in GitHub:
10+
https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series
11+
*/
12+
#include "heltec.h"
13+
#define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6
14+
15+
int counter = 0;
16+
#define Open_LED 12
17+
#define Close_LED 13
18+
void setup() {
19+
20+
//WIFI Kit series V1 not support Vext control
21+
Heltec.begin(false /*DisplayEnable Enable*/, true /*Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
22+
pinMode(Open_LED,INPUT);
23+
digitalWrite(Open_LED,LOW);
24+
pinMode(Close_LED,INPUT);
25+
digitalWrite(Close_LED,LOW);
26+
LoRa.setTxPower(14,RF_PACONFIG_PASELECT_PABOOST);
27+
28+
}
29+
30+
void loop() {
31+
if(digitalRead(Open_LED)){
32+
Serial.print("Sending packet: OpenLED\r\n");
33+
// send packet
34+
LoRa.beginPacket();
35+
LoRa.print("OpenLED");
36+
LoRa.endPacket();
37+
digitalWrite(Open_LED,LOW);
38+
}
39+
if(digitalRead(Close_LED)){
40+
Serial.print("Sending packet: CloseLED\r\n");
41+
// send packet
42+
LoRa.beginPacket();
43+
LoRa.print("CloseLED");
44+
LoRa.endPacket();
45+
digitalWrite(Close_LED,LOW);
46+
}
47+
delay(1000);
48+
}

0 commit comments

Comments
 (0)