Hi, I'm a beginner and not a programmer. I'm trying to get the LEDs to turn ON based on Serial Read, but the LEDs are not turning ON. I tried turning ON LED without serial read and the same works. Can some one guide me please.
Code:
int redLED=7;
int blueLED=9;
int grnLED=8;
String mycolor;
String msg1 ="What colour do u want the LED be?";
int wait=10000;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode (redLED, OUTPUT);
pinMode (blueLED, OUTPUT);
pinMode (grnLED, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(msg1);
while (Serial.available()==0){
}
mycolor =Serial.readString();
Serial.println(mycolor);
if (mycolor=="red"){
digitalWrite(redLED,HIGH);
digitalWrite(blueLED,LOW);
digitalWrite(grnLED,LOW);
}
if (mycolor=="blue"){
digitalWrite(redLED,LOW);
digitalWrite(blueLED,HIGH);
digitalWrite(grnLED,LOW);
}
if (mycolor=="green"){
digitalWrite(redLED,LOW);
digitalWrite(blueLED,LOW);
digitalWrite(grnLED,HIGH);
}
}
IO or Serial
What colour do u want the LED be?
red
What colour do u want the LED be?
red