Hey everyone i have encounterd a problem while trying to creat a project in which the user will input the LED color name and the right LED color will blink.
When i'm typing the LED color name it won't blink and im not sure why.
I have checked the components with individual digitalWrite command and they all work.
i'm assuming there is a problem with String reading or with the if statement.
I apolgize in advance for not using the function that makes the code visible as in the arduino coding program - I have simply haven't found here any instructions on how to do so, so I'd be glad if someone would shortly explaing how to do so also.
The code is as following:
String msg1 = "What color you want the LED to turn on?";
String LEDcolorpicked;
int yellowled = 2;
int redled = 3;
int blueled= 4;
void setup() {
// put your setup code here, to run once:
pinMode (yellowled,OUTPUT);
pinMode (redled,OUTPUT);
pinMode (blueled,OUTPUT);
Serial.begin (9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println (msg1);
while (Serial.available()==0){
}
LEDcolorpicked= Serial.readString();
Serial.println (LEDcolorpicked);
if (LEDcolorpicked=="yellow"){
digitalWrite (yellowled,HIGH);
digitalWrite (redled, LOW);
digitalWrite (blueled, LOW);
}
if (LEDcolorpicked == "red"){
digitalWrite (yellowled,LOW);
digitalWrite (redled, HIGH);
digitalWrite (blueled, LOW);
}
if (LEDcolorpicked == "blue"){
digitalWrite (yellowled,LOW);
digitalWrite (redled, LOW);
digitalWrite (blueled, HIGH);
}
}