expected unqualified-id before 'else'

Hello,
I did this code on my one with videos on the internet because i am still learning how to program arduino.

The code is basicaly a function that transforms a variable into a binary objects. On my breadboard I just connected 5 LEDs on pin 13, 12, 11, 10 and 9.
I have this error message: expected unqualified-id before 'else' at line 62.

Here is the code:

struct binary{
  bool LED1;
  bool LED2;
  bool LED4;
  bool LED8;
  bool LED16;
};

int minuteur = 0;
void light( binary );

void setup() {

 pinMode(8, INPUT);
 pinMode(9, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);
 pinMode(12, OUTPUT);
 pinMode(13, OUTPUT);
 Serial.begin(9600);
}

void loop() {
minuteur = 17;
delay(5000);
Serial.println(minuteur);

binary bin;
/*bin.LED1 = true;
bin.LED2 = false;
bin.LED4 = true;
bin.LED8 = false;
bin.LED16 = true; */

//bin = fonc on_convert(minuteur);
light( bin );
}

binary convert(int minuteur){
  binary bin;
  minuteur += 1;
  delay (5000);
  int reste = 0;
  bin.LED16,bin.LED8, bin.LED4, bin.LED2, bin.LED1 = LOW;
  if (minuteur/16 == 1){
   bin.LED16 = true;
   reste = minuteur % 16;
  }
   else if ( reste/8 == 1){
     bin.LED8 = true;
     reste = reste % 8;
   }
      else if ( reste/4 == 1){
      }
      bin.LED4 = true;
      reste = reste % 4;
      }
       else if (reste/2 == 1){
       bin.LED2 = true; 
       reste = reste % 2;
       }
        else if (reste/1 == 1){
        bin.LED1 = true;
        reste = reste % 1;
        }
 return bin;
}

void light(binary bin){
  if (bin.LED1){
 digitalWrite(13, HIGH);
  }
  else {
    digitalWrite(13, LOW);
  }
  if (bin.LED2){
    digitalWrite(12, HIGH);
  }
  else {
    digitalWrite(12, LOW);
    }
  if (bin.LED4){
    digitalWrite(11, HIGH);
  }
  else {
    digitalWrite(11, LOW);
  }
  if (bin.LED8){
    digitalWrite(10, HIGH);
  }
  else {
    digitalWrite(10, LOW);
  }
  if (bin.LED16){
     digitalWrite(9, HIGH);
  }
  else {
     digitalWrite(9, LOW);
  }
}

Thank you in advanced!!! :slight_smile:

check your braces

ctl-t to autoformat

  else if ( reste / 4 == 1)
  {
  }  //////// This looks like an extra bracket. Remove it.
  bin.LED4 = true;
  reste = reste % 4;
}

prolem solved thanks

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.