Arduino UNO - Strange LED Response to programming code

Hi guys,

I'm new to this, I just started my Electronics study over here in Holland.
This week they gave me an assignment:

  • Create a consecutive (back and forth) LED fade with 6 LEDs on the PWM outputs.

I'm getting the hang of it but I got a strange response from my set-up due to my code.
The LEDs go from 0 -> 5 (in an array) and back from 5 -> 0. After this, it's stuck on nr. 2
which keeps fading on and off.

My question is, can anybody tell me what's wrong with my code and why this is happening?
Thanks in advance!

Jelte

int ledPins[] = {
  3, 5, 6, 9, 10, 11 };       // an array of pin numbers to which LEDs are attached
int pinCount = 6;           // the number of pins (i.e. the length of the array)

void setup()
{ 
  int thisPin = 0;
  pinMode(ledPins[thisPin], OUTPUT);      
}

void loop()
{
  for (int thisPin = 0; thisPin < pinCount; thisPin++)
  {
    for (int fadeValue = 0; fadeValue <= 255; fadeValue +=5)
    {    
      analogWrite(ledPins[thisPin], fadeValue);
      delay(10);
    }
    for (int fadeValue = 255; fadeValue >= 0; fadeValue -=5)
    {
      analogWrite(ledPins[thisPin], fadeValue);
      delay(10);
    }
  }
  for (int thisPin = 4; thisPin < pinCount; thisPin--)
  {
    for (int fadeValue = 0; fadeValue <= 255; fadeValue +=5)
    {    
      analogWrite(ledPins[thisPin], fadeValue);
      delay(10);
    }
    for (int fadeValue = 255; fadeValue >= 0; fadeValue -=5)
    {
      analogWrite(ledPins[thisPin], fadeValue);
      delay(10);
    }
  }
}

Yes! That was the mistake I made.
Works perfectly now.

Appreciate your quick response!
Thanks!