Global vars corrupting [solved]

I know its bad practice, etc - and I think I'm learning why. I had originally set this up as a struct to be passed, but some other parts of the code broke (the tlc5904 library stopped responding) - for no apparent reason. The code is fairly straightforward - I'm trying to randomly fade 16 LED's. 3 global arrays - brightness, stepper (how much to increase or decrease brightness), and if the brightness is increasing or decreasing (updown). After a short time - stepper starts showing invalid values (should only be 2-20), updown begins to show non 0/1 values. I should have plenty of SRAM available - 15 * 3 * 16 = 720. I tried changing boards from a 328 duemilanove to a 328 Uno, and the behavior persisted.

Anyone give me a hint? Thanks.

#include "Tlc5940.h"

int brightness[15];
byte stepper[15];
byte updown[15];

//int min_inc = 2;
//int max_inc = 20;

void setup () {
  Serial.begin(115200);
  Tlc.init();
  randomSeed(analogRead(0));
  delay(30);
  Serial.println("Initialize...");

  for (int i = 0 ; i <= 15 ; i++) {
    brightness[i]=random(0, 4095);
    stepper[i]=random(2, 20);
    Tlc.set(i, brightness[i]);
    updown[i]=random(0,1);
  }
  Tlc.update();
  delay(3000);
}

void loop() {
  fade_calcs();
  delay(20);
  tx_tlc();
  delay(20);
  display_serial();
}

void tx_tlc() {
  Tlc.set(0, brightness[0]);
  Tlc.set(1, brightness[1]);
  Tlc.set(2, brightness[2]);
  Tlc.set(3, brightness[3]);
  Tlc.set(4, brightness[4]);
  Tlc.set(5, brightness[5]);
  Tlc.set(6, brightness[6]);
  Tlc.set(7, brightness[7]);
  Tlc.set(8, brightness[8]);
  Tlc.set(9, brightness[9]);
  Tlc.set(10, brightness[10]);  
  Tlc.set(11, brightness[11]);
  Tlc.set(12, brightness[12]);
  Tlc.set(13, brightness[13]);
  Tlc.set(14, brightness[14]);
  Tlc.set(15, brightness[15]);
  delay(1);
  Tlc.update();
  delay(1);
}

void fade_calcs() {
  for ( byte i = 0 ; i <= 15 ; i++ ) {
    
    if (updown[i]) {
    
      brightness[i] = brightness[i] + stepper[i];

      if ( brightness[i] >= 4095 ) {
        updown[i]=0; // change direction
        brightness[i] = brightness[i] - stepper[i];
      } // end inc
    } 
    else if (!updown[i]) {
      brightness[i] = brightness[i] - stepper[i];

      if ( brightness[i] <= 0 ) {
        brightness[i] = 0;
        updown[i]=1;
        stepper[i] = random(2, 20);      
      }
    } // end dec
  } // end for

}

void display_serial() {
  byte i = 1;
  Serial.print("i: ");
  Serial.print(i);
  Serial.print(" updown: ");
  Serial.print(updown[i]);
  Serial.print(" bright: ");
  Serial.print(brightness[i]);
  Serial.print(" rand: ");
  Serial.println(stepper[i]);
}

Serial output - rand should only rerandomize after brightness hits 0.

Initialize...
i: 0 updown: 2 bright: 1482 rand: 164
i: 0 updown: 2 bright: 1646 rand: 162
i: 0 updown: 2 bright: 1808 rand: 160
i: 0 updown: 2 bright: 1968 rand: 158
i: 0 updown: 2 bright: 2126 rand: 156
i: 0 updown: 2 bright: 2282 rand: 154
i: 0 updown: 2 bright: 2436 rand: 152
i: 0 updown: 2 bright: 2588 rand: 150
int brightness[15];

...

  Tlc.set(15, brightness[15]);

If you declare an array of size 15, the valid index values are 0 .. 14. When you access brightness [ 15 ] you're accessing memory outside the bounds of the array.

... of course it would be something simple. Thanks!

3 global arrays - brightness, stepper (how much to increase or decrease brightness), and if the brightness is increasing or decreasing (updown).

Why not make stepper do two things? stepper could have a value of +5 to increase in steps of 5, and a value of -5 to decrease in steps of 5. You don't need a separate variable to track whether the value of brightness is increasing or decreasing.