lewis.smith1652
So, I'm doing the 30 Days lost in space and I'm trying to write a code that will only allow one light to be on at a time. I wrote to code for the blue light and it worked. So I took that same bit of code, pasted it, and changed the color names. It's telling me I have an unqualified-id before the next "if" for the green switch. Can someone help me identify why this isn't working?

const byte BLUE_LIGHT = 10;
const byte GREEN_LIGHT = 11;
const byte YELLOW_LIGHT = 12;
const byte BLUE_SWITCH = 2;
const byte GREEN_SWITCH = 3;
const byte YELLOW_SWITCH = 4;

void setup() {
  // put your setup code here, to run once:

pinMode (BLUE_LIGHT,OUTPUT);
pinMode (GREEN_LIGHT,OUTPUT);
pinMode (YELLOW_LIGHT,OUTPUT);
pinMode (BLUE_SWITCH,INPUT);
pinMode (GREEN_SWITCH,INPUT);
pinMode (YELLOW_SWITCH,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead (BLUE_SWITCH) == HIGH){
    if(digitalRead(GREEN_SWITCH) == HIGH){
      digitalWrite (BLUE_LIGHT,LOW);}
      else if (digitalRead (YELLOW_SWITCH)==HIGH){
        digitalWrite(BLUE_LIGHT, LOW);}
        else{
          digitalWrite(BLUE_LIGHT, HIGH);
        }
      }
    }
 if (digitalRead (GREEN_SWITCH) == HIGH){
    if(digitalRead(BLUE_SWITCH) == HIGH){
      digitalWrite (BLUE_LIGHT,LOW);}
      else if (digitalRead (YELLOW_SWITCH)==HIGH){
        digitalWrite(GREEN_LIGHT, LOW);}
        else{
          digitalWrite(GREEN_LIGHT, HIGH);
        }
      }
    }
if (digitalRead (YELLOW_SWITCH) == HIGH){
    if(digitalRead(GREEN_SWITCH) == HIGH){
      digitalWrite (YELLOW_LIGHT,LOW);}
      else if (digitalRead (BLUE_SWITCH)==HIGH){
        digitalWrite(YELLOW_LIGHT, LOW);}
        else{
          digitalWrite(BLUE_LIGHT, HIGH);
        }
      }
    }
N3QGO
Get rid of the } above the lines 'if (digitalRead (GREEN_SWITCH) == HIGH){' and 'if (digitalRead (YELLOW_SWITCH) == HIGH){'. The extra } is closing the loop block.
Reply 1 0
Reply