Go Down

Topic: error: expected unqualified-id before 'if' (Read 783 times) previous topic - next topic

Hasi321

Nov 05, 2012, 11:10 am Last Edit: Nov 05, 2012, 11:20 am by Hasi321 Reason: 1
I get this error, when I try to compile it. My code begins like so:

Code: [Select]
#include <EEPROM.h>

const int buttonPin = 2;  //pushbutton
byte backlights = EEPROM.read(0);

if (backlights == 0){
 int Leds[10] = {3,4,5,6,7,8,13,13,13,13};  // array of the led numbers used, backlights will be turned on in setup()
}
else{
 int Leds[10] = {3,4,5,6,7,8,9,10,11,12};  // array of the led numbers used, boot normal
}

int reading;
boolean firstRun;

void setup() {


Why am I getting this error? Am I not allowed to use "if" outside a void?

pYro_65

if cannot be used at global scope like that, you need to do that setup routine in the setup() function.


pYro_65

Could set up common stuff globally, then do the unique stuff in setup().

Code: [Select]

int Leds[10] = {3,4,5,6,7,8};

void setup(){
  if( backlights ){
    Leds[ 6 ] = 9;
    Leds[ 7 ] = 10;
    Leds[ 8 ] = 11;
    Leds[ 9 ] = 12;
  }else{
    Leds[ 6 ] = Leds[ 7 ] = Leds[ 8 ] = Leds[ 9 ] = 13;
  }
}


Go Up