Hi.
I am learning how to code Arduino, but one of my first "projects" doesn't work. I'm working with an RGB LED and have connected it correctly, but there is something wrong with my code please help. This is my project: It looks at the serial monitor to see what color you have written and then lights the LED in that color, Here is my code
int redPin=8;
int greenPin=9;
int bluePin=10;
String myColor;
String msg="What color do you want?";
void setup() {
Serial.begin(9600);
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(msg);
while (Serial.available()==0){
}
myColor=Serial.readString();
if (myColor=="red"){
digitalWrite(redPin,HIGH);
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,LOW);
}
if (myColor=="green"){
digitalWrite(redPin,LOW);
digitalWrite(greenPin,HIGH);
digitalWrite(bluePin,LOW);
}
if (myColor=="blue"){
digitalWrite(redPin,LOW);
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,HIGH);
}
if (myColor=="off"){
digitalWrite(redPin,LOW);
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,LOW);
}
}