Pages: [1]   Go Down
Author Topic: error: expected unqualified-id before 'if'  (Read 729 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I get this error, when I try to compile it. My code begins like so:

Code:
#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?
« Last Edit: November 05, 2012, 05:20:12 am by Hasi321 » Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 65
Posts: 2111
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, ok thanks!
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 65
Posts: 2111
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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;
  }
}

Logged


Pages: [1]   Go Up
Jump to: