not declared in this scope errors ...

been a while since I toyed around with the IDE so upgraded to 1.6.5 from 1.0.*

I have a sketch which I'm 99.9% sure was working fine in the old IDE but now I am getting "not declared in this scope" errors for a number of variables. Has something changed in the way variables are declared in the updated IDE's?

code below for reference and the compiler complains about ledPin and Serial variables "not declared in this scope":

int lightReading = 0;

int numBlink[4] = {0, 1, 1, 2};

int ambientLight;
int darkThreshhold = 575;
int highCount = 0;
int lowCount = 0;

void setup(){
  int ledPins[3] = {6, 6, 6};
  Serial.begin(9600);
  pinMode(ledPins, OUTPUT);
  
}

void monitorLight(){
  highCount = 0;
  lowCount = 0;
  
    for(int i=0; i < 10; i++){
       lightReading = analogRead(A0);
       if (lightReading < darkThreshhold){
           highCount++;
       }else{
           lowCount++;
       }
          //Serial.println(highCount);
          //Serial.println(lowCount);
          //Serial.println(lightReading);
    delay(500);
  }
}


void selectPin(){
  //setup random 3 PWM pin selection function
  ledPin = random(0,4);
  ledPin = ledPins[ledPin];
  
}

void lightFly(){
  
      // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(10);       
    } 
}

void dimFly(){

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(10);                            
    } 
    
  }  

void loop(){
  
  Serial.println(analogRead(lightReading));
  
  analogWrite(ledPin[0], analogRead(lightReading)/4);
  
  delay(10);
  
}

ledPins[] is declared as a local variable in setup().
You cannot get to it in other sections.
Hence, it is out of scope as the error states.

Edit:
What are you trying to do here?
pinMode(ledPins, OUTPUT) ;

Where have you defined ledPin?
ledPin = random(0,4);
ledPin = ledPins[ledPin];

Have you read this?

.

The code you have posted could never have worked as it is.

For each out of scope error, you need to define the variable appropriately.

For example:
ledPin = random(0,4);

ledPin is not a defined variable in this scope, so you will get an error.

  int ledPins[3] = {6, 6, 6};

The Number of the Beast, eh?

So you have 3 LEDs, right? One is connected to pin 6, another is connected to pin 6, and the third is connected to pin 6. Have I got that right?

I have a couple of versions of this sketch, I had started tightening up the code from previous versions so maybe I chose one which was not working in earlier versions. Thanks for the references, I think I might have it from there...been a while since I picked this up so definitely very rusty.

as for int ledPins[3] = {6, 6, 6}; not an intentional thing although it crossed my mind that someone might pick that up :slight_smile:

It just happened to be the first PWM pin I looked over and chose.... for testing I didnt want to have to wire this up to 3 actual pins so I was being lazy I suppose! Figured once I had it working I'd adjust the array.

it is meant to simply pick a random LED of 3 and blink it a random number of blinks both based on the arrays there.

thanks for the pointers...I think I can straighten it out from there!