Hi, I would like to use my serial input to test my program using texts.
For instance, if I type the text "demo" in my serial monitor input, my program has to check this and then do something with it.
I am using Serial.readString() to get the input text. But if I use if to check the text that I enter, I alway get to see: "you started the demo routine".
What am I doing wrong?
Here's the code:
String incoming = ""; // for incoming serial string data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming:
incoming = Serial.readString();
// say what you got:
Serial.println(incoming);
if (incoming == 'demo') {
//demo routine
Serial.println("you started the demo routine");
}
else if (incoming=='sort') {
//sorteer routine
Serial.println("you started the sort routine");
}
else {
//junk
Serial.println("something else");
incoming = "";
}
Serial.flush();
}
}