Embedding photocell on/off "if" statements within a 6-LED loop...

Hey LED people!

I'm working on my first big Arduino project. To sum it up, I want 6 LED's to blink in order (1-6) 1 second apart, but furthermore, I want to have 6 photocells corresponding to each of the 6 LED's, so before say, LED 1 lights up, I want there to be an "if" statement (if photocell(1) < constant value) that determines whether LED 1 lights up or not before waiting one second to check if LED 2 should go on or not. Kinda tough stuff and I'm definitely an amateur.

So I have a snippet of a code from an example book:

int ledPins[] = {2,3};
int photoPins[] = {0,1};
int lightsOff = 300;

void setup()
{
  int index;
  
    for(index = 0; index <= 2; index++)
  {
    pinMode(ledPins[index],OUTPUT);
  }
  Serial.begin(9600);
}


void oneOnAtATime()
{
  int index;
  int delayTime = 5000; // milliseconds to pause between LEDs
  lightLevel = analogRead(photoPins[index]);
  
  for(index = 0; index <= 2; index++)
  {
    if (lightLevel > lightsOff) {
      
      digitalWrite(ledPins[index], HIGH);  // turn LED on
      delay(delayTime);          // pause to slow down
    }
    else {
      digitalWrite(ledPins[index], LOW);   // turn LED off
      delay(delayTime); 
    }
  }
}

Any thoughts on how I can stick both a for() and "if" statement in there for a series of 6 analogIn photocell values?

Thanks!

Zac

To make use a 6 LEDs instead of 2, you would just need to expand the arrays and loop sizes to cover 6 LEDs rather than 2.

Something like this would be the minimal changes you would need

byte photoPins[] = {0,1,2,3,4,5};  // assumes pins 0 to 5 are analog inputs
byte ledPins[] = {6,7,8,9,10,11};  // assumes pins 6 to 11 can be used to drive led outputs
int lightsOff = 300;

void setup() {

  for ( byte i = 0; i < 6; i++ ) {
    pinMode(ledPins[i], OUTPUT);
  }
  
  Serial.begin(9600);
}

void oneOnAtATime()
{
  
  int delayTime = 5000; // milliseconds to pause between LEDs
  lightLevel = analogRead(photoPins[index]);
  
  for(byte index = 0; index < 6; index++)
  {
    if (lightLevel > lightsOff) {
      
      digitalWrite(ledPins[index], HIGH);  // turn LED on
      delay(delayTime);                    // pause to slow down
    }
    else {
      digitalWrite(ledPins[index], LOW);   // turn LED off
      delay(delayTime); 
    }
  }
}

The ledPins[] array was expanded to 6 locations rather than 2, as well as the photoPins[] array.
Also made a small change to use byte variables rather than int types. This is to save memory on the Arduino. When declaring variables, you'd like to use the smallest ones you can to save RAM space.