Created
December 24, 2019 11:18
-
-
Save sidishere/0a068094437dfab5f15c7f245a91dc25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<SoftwareSerial.h> | |
#define led D5 | |
SoftwareSerial mySerial(D7,D8); | |
char command; | |
String string; | |
boolean ledon = false; | |
void setup(){ | |
Serial.begin(115200); | |
mySerial.begin(9600); | |
pinMode(led, OUTPUT); | |
} | |
void loop(){ | |
if (mySerial.available() > 0) { | |
string = ""; | |
} | |
while(mySerial.available() > 0) | |
{ | |
command = ((byte)mySerial.read()); | |
if(command == ':') { | |
break; | |
} | |
else { | |
string += command; | |
} | |
delay(1); | |
} | |
if(string == "TO"){ | |
ledOn(); ledon = true; | |
} | |
if(string =="TF"){ | |
ledOff(); | |
ledon = false; | |
Serial.println(string); //debug | |
} | |
if ((string.toInt()>=0)&&(string.toInt()<=255)) { | |
if (ledon==true) { | |
digitalWrite(led, HIGH); | |
Serial.println(string); //debug | |
delay(10); | |
} | |
} | |
} | |
void ledOn(){ | |
digitalWrite(led, HIGH); | |
delay(10); | |
} | |
void ledOff(){ | |
digitalWrite(led, LOW); | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment