Skip to content

Instantly share code, notes, and snippets.

@AgustinParmisano
Created April 7, 2017 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AgustinParmisano/c244d52cdf80409b18826d1095cd99fd to your computer and use it in GitHub Desktop.
Save AgustinParmisano/c244d52cdf80409b18826d1095cd99fd to your computer and use it in GitHub Desktop.
serial read string led blink
String readString;
String secret = "led";
String on = "on";
String off = "off";
int led = 13;
void setup() {
Serial.begin(9600);
Serial.println("Insert the password to blink the led!!");
}
void loop() {
while (Serial.available()) {
delay(2); //delay to allow byte to arrive in input buffer
char c = Serial.read();
readString += c;
readString.trim();
}
if (readString.length() >0) {
Serial.println(readString);
if(secret == readString) {
Serial.println("Unl0ck3d!!");
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
}
if(on == readString) {
Serial.println("L3d 0n!!");
digitalWrite(led, HIGH);
delay(1000);
}
if(off == readString) {
Serial.println("L3d 0ff!!");
digitalWrite(led, LOW);
delay(1000);
}
readString="";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment