Skip to content

Instantly share code, notes, and snippets.

@surinoel
Last active July 8, 2019 03:14
Show Gist options
  • Save surinoel/20d61220dc1eec3d8cff153fcc3b92f5 to your computer and use it in GitHub Desktop.
Save surinoel/20d61220dc1eec3d8cff153fcc3b92f5 to your computer and use it in GitHub Desktop.
int pinLED = 13;
int ledStatus = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(pinLED, OUTPUT);
Serial.println("usage : write (turn on | turn off)");
}
String Serialread()
{
String buf ="";
char c;
while(Serial.available() > 0) {
c = Serial.read();
buf.concat(c);
delay(10);
}
return buf;
}
void loop() {
// put your main code here, to run repeatedly:
String str = "";
digitalWrite(pinLED, ledStatus);
str = Serialread();
if(str == "") {
}
else if(str == "turn off") {
Serial.println(str);
ledStatus = 0;
}
else if(str == "turn on") {
Serial.println(str);
ledStatus = 1;
}
else {
Serial.println("usage : write (turn on | turn off)");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment