Analog read RGB LED

Hi, i am completely new to both coding and micro controllers, i am trying to learn coding best i can. the code below is supposed to ask for user input and activate the appropriate leg of the RGB led. I get the correct question on serial monitor, and it picks up the input as 'myColour' but nothing happens on the LED? there are no compiling or download errors showing up.

Sorry if this is a proper daft question, but when it doesn't work and you don't know why, its so frustrating!

int redLED = 6;
int greenLED = 5;
int blueLED = 3;
String msg="What colour do you want?";
String myColour;
String msg2="You chose ";


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);  
pinMode (redLED, OUTPUT);
pinMode (greenLED, OUTPUT);
pinMode (blueLED, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println(msg);
  while (Serial.available()==0) {
    
  }

myColour=Serial.readString();
Serial.print(msg2);
Serial.println(myColour);

  if (myColour=="red"){
analogWrite (redLED,255);
analogWrite (greenLED,0);
analogWrite (blueLED,0);
}

if (myColour="green"){
analogWrite (redLED,0);
analogWrite (greenLED,255);
analogWrite (blueLED,0);
}

if (myColour="blue"){
analogWrite (redLED,0);
analogWrite (greenLED,0);
analogWrite (blueLED,255);
}

if (myColour="off"){
analogWrite (redLED,0);
analogWrite (greenLED,0);
analogWrite (blueLED,0);
}
}/code]

What is the serial monitor line ending set to?

Not even sure what that means? I set up the serial monitor at the correct rate (9600) and store the input string as myColour .... the code works fine without the serial monitor part BTW ... so I know it’s something to do with my handling of the text input.

Told you I was new to this ..

if (myColour="green"){ that should be '==' as it is for "red" (also wrong on "blue" & "off")

Deva_Rishi:
if (myColour="green"){ that should be ‘==’ as it is for “red” (also wrong on “blue” & “off”)

Sometimes I look, and I just don’t see :frowning:

Thanks

reedmen:
Sorry if this is a proper daft question

The daft part is the thread title :wink: ... analog read an led?

Well I knew what I meant, just don’t know how to say it!!

It’s a learning curve and I’m still on the lower slopes!

reedmen:
It’s a learning curve and I’m still on the lower slopes!

We all have that t-shirt, don't worry.