0% found this document useful (0 votes)
7 views

Arduino

This Arduino code sets up a software serial communication with a LORA module and controls four LEDs based on button inputs and received commands. It toggles the LEDs on and off when buttons are pressed and listens for commands to turn the LEDs on or off via the LORA module. Additionally, it sends the status of the LEDs every 1500 milliseconds.

Uploaded by

desi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Arduino

This Arduino code sets up a software serial communication with a LORA module and controls four LEDs based on button inputs and received commands. It toggles the LEDs on and off when buttons are pressed and listens for commands to turn the LEDs on or off via the LORA module. Additionally, it sends the status of the LEDs every 1500 milliseconds.

Uploaded by

desi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <SoftwareSerial.

h>

SoftwareSerial LORA(2,3); // TX, RX

# define led1 4

# define led2 5

# define led3 6

# define led4 7

bool flag1= 1;

bool flag2= 1;

bool flag3= 1;

bool flag4= 1;

char leitura;

unsigned long tempo=0;

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

Serial.flush();

LORA.begin(9600);

LORA.flush();

pinMode(led1,OUTPUT);

pinMode(led2,OUTPUT);

pinMode(led3,OUTPUT);

pinMode(led4,OUTPUT);

pinMode(8,INPUT_PULLUP);

pinMode(9,INPUT_PULLUP);

pinMode(10,INPUT_PULLUP);

pinMode(11,INPUT_PULLUP);

tempo= millis();
}

void loop() {

// put your main code here, to run repeatedly:

if((digitalRead(8)==1)&&(flag1==1)){flag1=0;}

else if((digitalRead(8)==0)&&(flag1==0)){

flag1=1;

digitalWrite(led1, !digitalRead(led1));

//

if((digitalRead(9)==1)&&(flag2==1)){flag2=0;}

else if((digitalRead(9)==0)&&(flag2==0)){

flag2=1;

digitalWrite(led2, !digitalRead(led2));

//

if((digitalRead(10)==1)&&(flag3==1)){flag3=0;}

else if((digitalRead(10)==0)&&(flag3==0)){

flag3=1;

digitalWrite(led3, !digitalRead(led3));

//

if((digitalRead(11)==1)&&(flag4==1)){flag4=0;}

else if((digitalRead(11)==0)&&(flag4==0)){

flag4=1;

digitalWrite(led4, !digitalRead(led4));

//
if(LORA.available()){

String leitura=LORA.readString();

if(leitura=="led1on"){digitalWrite(led1,HIGH);}

if(leitura=="led2on"){digitalWrite(led2,HIGH);}

if(leitura=="led3on"){digitalWrite(led3,HIGH);}

if(leitura=="led4on"){digitalWrite(led4,HIGH);}

if(leitura=="led1off"){digitalWrite(led1,LOW);}

if(leitura=="led2off"){digitalWrite(led2,LOW);}

if(leitura=="led3off"){digitalWrite(led3,LOW);}

if(leitura=="led4off"){digitalWrite(led4,LOW);}

if(millis()-tempo>1500){

tempo = millis();

if(digitalRead(led1)==1){LORA.print("1");}

else if(digitalRead(led1)==0){LORA.print("2");}

if(digitalRead(led2)==1){LORA.print("*3");}

else if(digitalRead(led2)==0){LORA.print("*4");}

if(digitalRead(led3)==1){LORA.print("*5");}

else if(digitalRead(led3)==0){LORA.print("*6");}

if(digitalRead(led4)==1){LORA.print("*7");}

else if(digitalRead(led4)==0){LORA.print("*8");}

LORA.println(" ");

}}

You might also like