Newbie issue R4 WifI

Lesson 17 Paul McWhorter Uno R4 wifi. Can't get the LED's to turn on. Checked the wiring with digitalWrite, LED's function manually. It seems like the program never executes the if statements. Reviewed the vid multiple times. Stumped. Hope this is the correct place to post this question. thank you.

int redPin=9;
int yellowPin=10;
int greenPin=11;
String userColor;
String userPrompt="Please select red, yellow, green LED color-";

void setup() {
  // put your setup code here, to run once:
Serial.begin (9600);
pinMode(redPin,OUTPUT);
pinMode(yellowPin,OUTPUT);
pinMode(greenPin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  //ASK
 Serial.println (userPrompt);
  //WAIT
  while (Serial.available()==0) {
}
  //READ
userColor=Serial.readString();
userColor.toLowerCase();
 
 if (userColor=="red") {
  digitalWrite (redPin,HIGH);
  digitalWrite (yellowPin,LOW);
  digitalWrite (greenPin,LOW);
  Serial.println (userColor);
  }
 if (userColor=="yellow") {
  digitalWrite (redPin,LOW);
  digitalWrite (yellowPin,HIGH);
  digitalWrite (greenPin,LOW);
   Serial.println (userColor);
 }
 if (userColor=="green") {
  digitalWrite (redPin,LOW);
  digitalWrite (yellowPin,LOW);
  digitalWrite (greenPin,HIGH);
  Serial.println (userColor);
}
}

Are you seeing the colors printing back on the serial monitor?

Another thing to check is that you have “no line ending” selected on the serial monitor. That is probably not the actual selection but I know Paul emphasizes that in his videos.

thanks for the reply. No, I don't see colors red, yellow, green print on SM, however, if I add Serial.println (userColor); before the if statements, colors do print on SM.

What about “no line ending”?

1 Like

Sorry, showing my ignorance. "No line ending"?

It is a setting in the SM. Choices are:

No line ending
Carriage return
Line feed
LF/CR

it is in the upper right corner of the monitor and should be set to “no line ending”.

Great! thank you. I set to "no line ending" and the code works. Much appreciated.

Wow! I actually helped. I feel great!

I am not sure but I think

userColor.trim;

Would have taken out line endings too.

I am a noob too, mostly to C++ but I have been programming things for over 40 years. Arduino for one year.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.