/*
Blink LED with uart / printf
*/
String received_command;
char incomingByte;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
Serial1.begin(115200);
Serial1.println("Press ENTER to start!");
delay(500);
// Wait until a newline character is received
while (incomingByte != '\n') {
if (Serial1.available() > 0) {
incomingByte = Serial1.read();
}
}
Serial1.println("Send 'LED ON' or 'LED OFF'\n");
}
void loop() {
if (Serial1.available() > 0) {
// Read input until newline and clean it
received_command = Serial1.readStringUntil('\n');
//received_command.trim(); // remove any trailing \r or spaces
Serial1.print("Received Command: ");
Serial1.println(received_command);
// Act on command
if (received_command == "LED ON") {
digitalWrite(LED_BUILTIN, HIGH);
Serial1.println("LED turned ON");
}
else if (received_command == "LED OFF") {
digitalWrite(LED_BUILTIN, LOW);
Serial1.println("LED turned OFF");
}
else {
Serial1.println("Command is wrong!");
}
}
}