Putting Fade and Multiple LED sketches together, but only one LED works

Greetings all,
I'm attempting to light 6 Led's one at a time, one after another by fading them up, then back down, and on to the next LED. Using the code below, I only get the first LED to come on Fade ON, then turn completely off (NO FADE out), then repeat. Could someone please look at my code and tell me what I'm doing wrong? Be easy, I'm new to the Arduino world!!

int ledPins[] = {3,5,6,9,10,11};
int brightness = 0;
int fadeAmount = 5;

void setup()

{
int index;
for(index = 0; index <=5; index++)
{
pinMode(ledPins[index], OUTPUT);
}
}

void loop()
{
fadeoneAfteranotherLoop();
}
void fadeoneAfteranotherLoop()
{
int index;
int delayTime = 20;

for(index = 0; index <=5; index++);
{
analogWrite(ledPins[index], brightness);

brightness = brightness + fadeAmount;

if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}

delay(delayTime);

}}

Thanks,
Harry

When behavior like this exhibits itself, the usual question is does changing the order of the pins in the array change which one works correctly?

If it's always the same pin that works, the others are wired wrong. If it's always the same position that works, the code is wrong.

One } per line. NEVER more than one.

Use Tools + Auto Format before you post any more improperly indented code. And, use the # icon above the row of smiley faces to generate code tags that you post code between.

Thanks for the advice,
I hope this is better.

int ledPins[] = {
  3,5,6,9,10,11};
int brightness = 0;
int fadeAmount = 5;

void setup() 

{
  int index;
  for(index = 0; index <=5; index++)
  {
    pinMode(ledPins[index], OUTPUT);
  }
}
// the loop routine runs over and over again forever:
void loop()  
{ 
  fadeoneAfteranotherLoop();
}
void fadeoneAfteranotherLoop()
{
  int index;
  int delayTime = 20;

  for(index = 0; index <=5; index++);
  {
    analogWrite(ledPins[index], brightness);    

    brightness = brightness + fadeAmount;


    if (brightness == 0 || brightness == 255) {
      fadeAmount = -fadeAmount ; 
    } 

    delay(delayTime);                            

  }
}

The code looks better (except for the unnecessary blank lines), but you didn't answer the questions.

Does changing the order of the pin numbers in the array have any effect?

I'm pretty sure the code is wrong, because changing the order of the pins does not affect the behavior. The same pin still fades on, turns off (no fade) , and then fades on again. If I change the [index] in line 24 to an actual number, [0] then the LED fades on, and then fades off correctly, but doesn't advance to the next LED.

int ledPins[] = {
  11,10,9,6,5,3};
int brightness = 0;
int fadeAmount = 5;
void setup() 
{
  int index;
  for(index = 0; index <=5; index++)
  {
    pinMode(ledPins[index], OUTPUT);
  }
}
// the loop routine runs over and over again forever:
void loop()  
{ 
  fadeoneAfteranotherLoop();
}
void fadeoneAfteranotherLoop()
{
  int index;
  int delayTime = 20;
  for(index = 0; index <=5; index++);
  {
    analogWrite(ledPins[index], brightness);    
    brightness = brightness + fadeAmount;
    if (brightness == 0 || brightness == 255) {
      fadeAmount = -fadeAmount ; 
    } 
    delay(delayTime);                            
  }
}

Each time you call the function, it should change the state of all 6 pins. If that is not appearing to happen, it could be a hardware problem.

Instead of fading, scrap that code, and simply turn the pin on in the for loop. Assure that all 6 LEDs come on before trying to get fancy.

I figured out the error of my ways, but haven't come up with a fix yet.

The problem is that the fade function is constantly changing the brightness from 0 -> 255, then reversing it from 255 -> 0, then repeating so it never advances. Is there a way I could make it count cycles from 0 ->255 -> 0, and then advance to the next LED?

The problem is that the fade function is constantly changing the brightness from 0 -> 255, then reversing it from 255 -> 0, then repeating so it never advances

I'm not following that. brightness does indeed increase and decrease, but only as the for loop iterates. As the for loop iterates, it should be applying brightness to each pin in turn. The pins will increase in brightness in steps of 25, with no two at the same level at any time, which may not have been what you wanted, but, still, all 6 LEDs should be fading up and down.

So, what never advances?