I am trying to make a program that just turns on one of three lights when their correspondent color is inputted. The circuit works fine as I set all of the lights to HIGH just to see if they would go off and they did so I think the code is the problem.
String msg="What color light do you want";
String Color;
int bluepin=7;
int greenpin=2;
int redpin=4;
void setup() {
// put your setup code here, to run once:
pinMode(greenpin,OUTPUT);
pinMode(bluepin,OUTPUT);
pinMode(redpin,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(msg);
while(Serial.available()==0){
}
Color=Serial.readString();
if(Color=="red"){
digitalWrite(redpin,HIGH);
digitalWrite(bluepin,LOW);
digitalWrite(greenpin,LOW);
}
if(Color=="green"){
digitalWrite(greenpin,HIGH);
digitalWrite(redpin,LOW);
digitalWrite(bluepin,LOW);
}
if(Color=="blue"){
digitalWrite(bluepin,HIGH);
digitalWrite(redpin,LOW);
digitalWrite(greenpin,LOW);
}
}
anyone know where I went wrong?