So just working with a very simple sketch using a Arduino Nana flashed to Uno . Not sure if that matters or not but what I am seeing is that I get what I expect for the most part from the serial monitor but what I call an echo. The sketch just ask which led color do you want to turn on and when you have answered the question properly it in deed turns on the led and prints the message "you selected red led" which is fine but then the next comes up with the question as it should but it also shows the color selected in the question. example :
What color do you want ?
You selected Red Led
What color do you want ? red
Doesn't affect the circuit but just looks bad in the serial monitor.
Serial monitor has to be set No Line Ending and baud rate doesn't affect anything , send it to serial monitor as a Uno or a Nano does not make a difference. I am sure it's the way I am writing the code, can someone point me in the right direction?
edited to remove space at the begining of the text, this is interpreted as code otherwise and makes the post unreadable. Please just type your text aligned to the left
String myColor;
int redLed = 8;
int blueLed = 7;
int greenLed = 6;
String msg = " What color do you want ?";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(redLed, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print(msg);
Serial.println(myColor);
while (Serial.available() == 0) {
}
myColor = Serial.readString();
if (myColor == ("red")) {
digitalWrite(redLed, HIGH);
Serial.println(" You Selected Red Led");
}
}