#define LED 7
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.setTimeout(1000);
// demo led output
pinMode(LED, OUTPUT); // sets the LED Pin as output
digitalWrite(LED, LOW); // initial OFF
}
void loop() {
String input;
char any;
Serial.println("Waiting for command...");
while (Serial.available() == 0) {
// you can do something if no data is available
}
String command = Serial.readString(); //read until timeout (see setTimeout line #4 for ms)
command.trim(); // remove any \r \n whitespace at the end of the String
Serial.print("Received command:");
Serial.println(command);
if (command == "on") {
digitalWrite(LED, HIGH);
Serial.println("DONE: Switching ON");
}
else if (command == "off") {
digitalWrite(LED, LOW);
Serial.println("DONE: Switching OFF");
}
else {
Serial.println("Unknown command");
}
}