Can someone help me with my LED sequencer?

arduino noob here! need help!

So my LED sequencer has 2 buttons and one pot.

the pot controls the speed

a mode button (choose between normal, knight rider, or random)

and a length button (to choose the pins i'm using 1-8 or 1-7 etc.)

everything works fine, but my friggin length button seems to be messing with the variable whatPin

i think its a logic error but i can't figure it out - i've tried reorganizing things various ways... this is the latest incarnation

i've left out the knightrider function and the random function because the code was too big

const int ledPin =  13;      // the number of the LED pin
const int ledPin2 = 12;
const int ledPin3 = 11;
const int ledPin4 = 10;
const int ledPin5 = 9;
const int ledPin6 = 8;
const int ledPin7 = 7;
const int ledPin8 = 6;
const int speedPin = 1;
const int  modeButtonPin = 2;    // the pin that the pushmodeButton is attached to
const int lengthButtonPin = 3;

int led;

int lengthButtonState;
int lastLengthButtonState;
int lengthButtonCounter;

long lastDebounceTime;
int debounceDelay = 200;

int modeButtonPushCounter = 0;   // counter for the number of modeButton presses
int modeButtonState = 0;         // current state of the modeButton
int lastModeButtonState = 0;     // previous state of the modeButton

int whatPin = 0;                //variable to decide which relay to open
int previousWhatPin = 0;        // on the random function this will store which pin was triggered last
long previousMillis = 0;        // will store last time relay was updated
long interval = 0;           // interval at which to blink (controlled by speed pin)

void setup() {

  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);

  pinMode(speedPin, INPUT); 
  pinMode(modeButtonPin, INPUT);
  pinMode(lengthButtonPin, INPUT);

  Serial.begin(9600);

}

void loop() {

  // lighting the leds

  switch (led) {
  case 1:
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin6, LOW);
    digitalWrite(ledPin7, LOW);
    digitalWrite(ledPin8, LOW); 
    digitalWrite(ledPin, HIGH);    
    break;
  case 2:   
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin6, LOW);
    digitalWrite(ledPin7, LOW);
    digitalWrite(ledPin8, LOW);   
    digitalWrite(ledPin2, HIGH);   
    break;
  case 3:
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin6, LOW);
    digitalWrite(ledPin7, LOW);
    digitalWrite(ledPin8, LOW);    
    digitalWrite(ledPin3, HIGH);  
    break;
  case 4:
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin6, LOW);
    digitalWrite(ledPin7, LOW);
    digitalWrite(ledPin8, LOW); 
    digitalWrite(ledPin4, HIGH);
    break;
  case 5:
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin6, LOW);
    digitalWrite(ledPin7, LOW);
    digitalWrite(ledPin8, LOW);   
    digitalWrite(ledPin5, HIGH);       
    break;
  case 6:
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin7, LOW);
    digitalWrite(ledPin8, LOW);    
    digitalWrite(ledPin6, HIGH);  
    break;
  case 7:
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin6, LOW);
    digitalWrite(ledPin8, LOW);  
    digitalWrite(ledPin7, HIGH);    
    break;
  case 8:
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin6, LOW);
    digitalWrite(ledPin7, LOW);  
    digitalWrite(ledPin8, HIGH);    
    break;    
  }


  //Check Keys

  //Check Speed

  interval = analogRead(speedPin);

  //Check Length

  lengthButtonState = digitalRead(lengthButtonPin);


  if (lengthButtonState != lastLengthButtonState){
    lastLengthButtonState = lengthButtonState;
    if (lengthButtonState == HIGH){
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);  
      digitalWrite(ledPin8, LOW);  
      lengthButtonCounter++;
      if(lengthButtonCounter >= 7){
        lengthButtonCounter = 0;
      }   
    }
  }


  //Check Mode

  modeButtonState = digitalRead(modeButtonPin);

  if (modeButtonState != lastModeButtonState) {
    lastModeButtonState = modeButtonState;
    if (modeButtonState == HIGH) {
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);  
      digitalWrite(ledPin8, LOW);  
      modeButtonPushCounter++;
      if(modeButtonPushCounter >=3){
        modeButtonPushCounter = 0;
      }
    } 

  }

  if(modeButtonPushCounter == 0){

    if(lengthButtonCounter == 0){
      normal8();
    }
    if(lengthButtonCounter == 1){
      normal7();
    }
    if(lengthButtonCounter == 2){
      normal6();
    }
    if(lengthButtonCounter == 3){
      normal5();
    }
    if(lengthButtonCounter == 4){
      normal4();
    }
    if(lengthButtonCounter == 5){
      normal3();
    }
    if(lengthButtonCounter == 6){
      normal2();
    }

  }

  if(modeButtonPushCounter == 1){   
    knightRider(); 
  }
  if(modeButtonPushCounter == 2){
    crazy(); 
  }
  if(modeButtonPushCounter >= 3){
    modeButtonPushCounter = 0;
  }

}

void normal8(){

  if (millis() - previousMillis > interval) {

    previousMillis = millis();

    whatPin = whatPin + 1;

    if (whatPin == 1){
      led = 1;
    }
    if (whatPin == 2){
      led = 2;
    }
    if (whatPin == 3){
      led = 3;
    }
    if (whatPin == 4){
      led = 4;
    }
    if (whatPin == 5){
      led = 5;
    }
    if (whatPin == 6){
      led = 6;
    }
    if (whatPin == 7){
      led = 7;
    }
    if (whatPin == 8){
      led = 8;
      whatPin = 0;      
    }
  }
}

void normal7(){

  if (millis() - previousMillis > interval) {

    previousMillis = millis();

    whatPin = whatPin + 1;

    if (whatPin == 1){
      led = 1;
    }
    if (whatPin == 2){
      led = 2;
    }
    if (whatPin == 3){
      led = 3;
    }
    if (whatPin == 4){
      led = 4;
    }
    if (whatPin == 5){
      led = 5;
    }
    if (whatPin == 6){
      led = 6;
    }
    if (whatPin == 7){
 led = 7;
      whatPin = 0;      
    }
  }
}

void normal6(){

  if (millis() - previousMillis > interval) {

    previousMillis = millis();

    whatPin = whatPin + 1;

    if (whatPin == 1){
      led = 1;
    }
    if (whatPin == 2){
      led = 2;
    }
    if (whatPin == 3){
      led = 3;
    }
    if (whatPin == 4){
      led = 4;
    }
    if (whatPin == 5){
      led = 5;
    }
    if (whatPin == 6){
      led = 6;
      whatPin = 0;      
    }
  }
}

void normal5(){

  if (millis() - previousMillis > interval) {

    previousMillis = millis();

    whatPin = whatPin + 1;

    if (whatPin == 1){
      led = 1;
    }
    if (whatPin == 2){
      led = 2;
    }
    if (whatPin == 3){
      led = 3;
    }
    if (whatPin == 4){
      led = 4;
    }
    if (whatPin == 5){
      led = 5;
      whatPin = 0;      
    }
  }
}

void normal4(){

  if (millis() - previousMillis > interval) {

    previousMillis = millis();

    whatPin = whatPin + 1;

    if (whatPin == 1){
      led = 1;
    }
    if (whatPin == 2){
      led = 2;
    }
    if (whatPin == 3){
      led = 3;
    }
    if (whatPin == 4){
      led = 4;
      whatPin = 0;      
    }
  }
}

void normal3(){

  if (millis() - previousMillis > interval) {

    previousMillis = millis();

    whatPin = whatPin + 1;

    if (whatPin == 1){
      led = 1;
    }
    if (whatPin == 2){
      led = 2;
    }
    if (whatPin == 3){
      led = 3;
      whatPin = 0;      
    }
  }
}

void normal2(){

  if (millis() - previousMillis > interval) {

    previousMillis = millis();

    whatPin = whatPin + 1;

    if (whatPin == 1){
      led = 1;
    }
    if (whatPin == 2){
      led = 2;
      whatPin = 0;      
    }
  }
}

here is some updated code but it still does the same thing

when i Serial.print(whatPin) anywhere outside of the function the arduino program on my PC crashes

i pasted that modulo thing in the code... actually made nothing blink

const int ledPin =  13;      // the number of the LED pin
const int ledPin2 = 12;
const int ledPin3 = 11;
const int ledPin4 = 10;
const int ledPin5 = 9;
const int ledPin6 = 8;
const int ledPin7 = 7;
const int ledPin8 = 6;
const int speedPin = 1;
const int  modeButtonPin = 2;    // the pin that the pushmodeButton is attached to
const int lengthButtonPin = 5;

int led;

int lengthButtonState;
int lastLengthButtonState;
int lengthButtonCounter;

int modeButtonPushCounter = 0;   // counter for the number of modeButton presses
int modeButtonState = 0;         // current state of the modeButton
int lastModeButtonState = 0;     // previous state of the modeButton

int whatPin;
int previousWhatPin = 0;        // on the random function this will store which pin was triggered last
unsigned long previousMillis = 0;        // will store last time relay was updated
unsigned long interval = 0;           // interval at which to blink (controlled by speed pin)

void setup() {

  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);

  pinMode(speedPin, INPUT); 
  pinMode(modeButtonPin, INPUT);
  pinMode(lengthButtonPin, INPUT);

  Serial.begin(9600);

}

void loop() {
  
      // lighting the leds

    switch (led) {
    case 1:
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);
      digitalWrite(ledPin8, LOW); 
      digitalWrite(ledPin, HIGH);    
      break;
    case 2:   
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);
      digitalWrite(ledPin8, LOW);   
      digitalWrite(ledPin2, HIGH);   
      break;
    case 3:
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);
      digitalWrite(ledPin8, LOW);    
      digitalWrite(ledPin3, HIGH);  
      break;
    case 4:
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);
      digitalWrite(ledPin8, LOW); 
      digitalWrite(ledPin4, HIGH);
      break;
    case 5:
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);
      digitalWrite(ledPin8, LOW);   
      digitalWrite(ledPin5, HIGH);       
      break;
    case 6:
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin7, LOW);
      digitalWrite(ledPin8, LOW);    
      digitalWrite(ledPin6, HIGH);  
      break;
    case 7:
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin8, LOW);  
      digitalWrite(ledPin7, HIGH);    
      break;
    case 8:
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);  
      digitalWrite(ledPin8, HIGH);    
      break;    
    }

  //Check Keys

  //Check Speed

  interval = analogRead(speedPin);

  //Check Length

  lengthButtonState = digitalRead(lengthButtonPin);


  if (lengthButtonState != lastLengthButtonState){
    lastLengthButtonState = lengthButtonState;
    if (lengthButtonState == HIGH){
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);  
      digitalWrite(ledPin8, LOW);  
      lengthButtonCounter++;
      if(lengthButtonCounter >= 7){
        lengthButtonCounter = 0;
      }   
    }
  }


  //Check Mode

  modeButtonState = digitalRead(modeButtonPin);

  if (modeButtonState != lastModeButtonState) {
    lastModeButtonState = modeButtonState;
    if (modeButtonState == HIGH) {
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);  
      digitalWrite(ledPin8, LOW);  
      modeButtonPushCounter++;
      if(modeButtonPushCounter >=3){
        modeButtonPushCounter = 0;
      }
    } 

  }

  if(modeButtonPushCounter == 0){
    
    normal();
  }

  if(modeButtonPushCounter == 1){   
    knightRider(); 
  }
  if(modeButtonPushCounter == 2){
    crazy(); 
  }
  if(modeButtonPushCounter >= 3){
    modeButtonPushCounter = 0;
  }

}

void normal(){

  if (millis() - previousMillis > interval) {

    previousMillis = millis();

    whatPin = whatPin + 1;

    if (whatPin == 1){
      led = 1;
    }
    if (whatPin == 2){
      led = 2;
      if(lengthButtonCounter == 6){
        whatPin = 0;   
      }   
    }
    if (whatPin == 3){
      led = 3;
      if(lengthButtonCounter == 5){
        whatPin = 0;   
      }   
    }
    if (whatPin == 4){
      led = 4;
      if(lengthButtonCounter == 4){
        whatPin = 0;   
      }   
    }
    if (whatPin == 5){
      led = 5;
      if(lengthButtonCounter == 3){
        whatPin = 0;   
      }   
    }
    if (whatPin == 6){
      led = 6;
      if(lengthButtonCounter == 2){
        whatPin = 0;   
      }   
    }
    if (whatPin == 7){
      led = 7;
      if(lengthButtonCounter == 1){
        whatPin = 0;   
      }   
    }
    if (whatPin == 8){
      led = 8;
      if(lengthButtonCounter == 0){
        whatPin = 0;   
      }   
    }
  }
}


void knightRider(){

  if (millis() - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = millis();

    whatPin = whatPin + 1;

    if (whatPin == 1){
      led = 1;
    }
    if (whatPin == 2){
      led = 2;
    }
    if (whatPin == 3){
      led = 3;
    }
    if (whatPin == 4){
      led = 4;
    }
    if (whatPin == 5){
      led = 5;
    }
    if (whatPin == 6){
      led = 6;
    }
    if (whatPin == 7){
      led = 7;
    }
    if (whatPin == 8){
      led = 8;
    }
    if (whatPin == 9){
      led = 7;
    }
    if (whatPin == 10){
      led = 6;
    }
    if (whatPin == 11){
      led = 5;
    }
    if (whatPin == 12){
      led = 4;
    }
    if (whatPin == 13){
      led = 3;
    }
    if (whatPin == 14){
      led = 2;
      whatPin = 0;
    }
  }
}

void crazy(){

  if (millis() - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = millis();

    whatPin = int(random(0,8));

    if(whatPin == previousWhatPin){
      whatPin++; 
      if(whatPin >= 8){
        whatPin = 1;
      }
    }

    if (whatPin == 0){
      led = 1;
      previousWhatPin = whatPin;
    }

    if (whatPin == 1){
      led = 2;
      previousWhatPin = whatPin;
    }

    if (whatPin == 2){
      led = 3;
      previousWhatPin = whatPin;
    }

    if (whatPin == 3){
      led = 4;
      previousWhatPin = whatPin;

    }
    if (whatPin == 4){
      led = 5;
      previousWhatPin = whatPin;
    }

    if (whatPin == 5){
      led = 6;
      previousWhatPin = whatPin;
    }

    if (whatPin == 6){
      led = 7;
      previousWhatPin = whatPin;
    }

    if (whatPin == 7){    
      led = 8;
      previousWhatPin = whatPin;
    }
  }
}
int led;
void loop() {
  
      // lighting the leds

    switch (led) {

What value does led have in it?

int whatPin;
    whatPin = whatPin + 1;

What value does whatPin have in it?

when i Serial.print(whatPin) anywhere outside of the function the arduino program on my PC crashes

Outside of what function? How does sending serial data to the PC cause it to crash?

well - after i hit the length button (rapidly) a couple times - i see some zeros and then the numbers get all wacky - like not 1,2,3,4,5,6, etc. starts doing weird stuff (that is if i do a serial print on whatPin inside the funciton)

it never messes up the same way twice - its always kinda random - like it might get 3 or 4 button presses in and then it messes up

basically winds up that led 8 is just on and nothing else is moving

if i do a serial print on whatPin outside of the function the arduino program seems to freeze and then i have to CTL ALT DEL the program.

i have to check the serial print on led still... havent had a chance - thanks for helping a bit! ill get back to ya later tonight probs.

  if (lengthButtonState != lastLengthButtonState){
    lastLengthButtonState = lengthButtonState;
    if (lengthButtonState == HIGH){

This code is only recording the previous button state, if it’s different. The previous button state should always be set to the current button state.

I would suggest that you create an array of led pins, instead of 8 separate values:

int pinCnt = 8;
int ledPins[] = {13, 12, 11, 10, 9, 8, 7, 6};

This way, you can turn all the LEDs off with this:

for(int i=0; i<ledCnt; i++)
{
    digitalWrite(ledPins[i], LOW);
}

Put that code in a function, called allOff, and turn all the LEDs off with one line of code:

allOff();

The whole switch statement can be reduced to:

allOff();
digitalWrite(ledPins[led], HIGH);

While your fixing switch statements, the normal() function is crying out for a switch statement, instead of all those if statements.

The reason I was asking about the values in led and whatPin was to give you a hint to look at the code. You did not initialize led or whatPin, so you’re relying on the compiler to have done that for you. It’s much better to get in the habit of typing “variableType variableName = initialValue;” than it is to get in the habit of letting the compiler initialize variables for you.

I know I stress this a lot, but I once worked on a system where all non-explicitly initialized variables were initialized to 3087, rather than 0. Odd behavior was easily traced to non-initialized variables on that system.

wow! thanks a ton - i should have come to this forum a long time ago. that was really clear and understandable. i think i need to rewrite this using arrays.

ok - i get what you mean about the array, fixing the switch cases and initializing the variables in the begining - but i still don’t understand what you mean about the length button. I tried to debounce it but i think i just don’t get it. can you expand on that?

broke a bunch of stuff up into functions - i just want to get the normal mode working with the length button so it cuts off a pin everytime i push the button - i don’t understand why my mode button would work flawlessly, but the length button just makes stuff crash. its the same code. i remember someone telling me about passing variables - does it have something to do with that?

thanks for your help!

int ledCnt = 8;
int ledPins[8] = {
  13, 12, 11, 10, 9, 8, 7, 6}; 
const int speedPin = 1;
const int  modeButtonPin = 2;    // the pin that the pushmodeButton is attached to
const int lengthButtonPin = 5;

int led = 1;

int lengthButtonState = 0;
int lastLengthButtonState = 0;
int lengthButtonCounter = 0;

int modeButtonPushCounter = 0;   // counter for the number of modeButton presses
int modeButtonState = 0;         // current state of the modeButton
int lastModeButtonState = 0;     // previous state of the modeButton

int whatPin = 0;
int previousWhatPin = 0;        // on the random function this will store which pin was triggered last
unsigned long previousMillis = 0;        // will store last time relay was updated
unsigned long interval = 0;           // interval at which to blink (controlled by speed pin)

void setup() {

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

  pinMode(speedPin, INPUT); 
  pinMode(modeButtonPin, INPUT);
  pinMode(lengthButtonPin, INPUT);

  Serial.begin(9600);

}

void loop() {

  // lighting the leds

  //Check Keys

  //Check Speed

  interval = analogRead(speedPin);

  //Check Length

  lengthButtonState = digitalRead(lengthButtonPin);


  if (lengthButtonState != lastLengthButtonState){
    lastLengthButtonState = lengthButtonState;
    if (lengthButtonState == HIGH){
      allOff();
      lengthButtonCounter++;
      if(lengthButtonCounter >= 7){
        lengthButtonCounter = 0;
      }   
    }
  }


  //Check Mode

  modeButtonState = digitalRead(modeButtonPin);

  if (modeButtonState != lastModeButtonState) {
    lastModeButtonState = modeButtonState;
    if (modeButtonState == HIGH) {
      allOff();
      modeButtonPushCounter++;
      if(modeButtonPushCounter >=3){
        modeButtonPushCounter = 0;
      }
    } 

  }

  if(modeButtonPushCounter == 0){

    normal();
  }

  if(modeButtonPushCounter == 1){   
    knightRider(); 
  }
  if(modeButtonPushCounter == 2){
    crazy(); 
  }
  if(modeButtonPushCounter >= 3){
    modeButtonPushCounter = 0;
  }

}

void normal(){

  if (millis() - previousMillis > interval) {

    previousMillis = millis();

    whatPin = whatPin + 1;

    if (whatPin == 1){
      led1();
    }
    if (whatPin == 2){
      led2();
      if(lengthButtonCounter == 6){
        whatPin = 0;   
      }   
    }
    if (whatPin == 3){
      led3();
      if(lengthButtonCounter == 5){
        whatPin = 0;   
      }   
    }
    if (whatPin == 4){
      led4();
      if(lengthButtonCounter == 4){
        whatPin = 0;   
      }   
    }
    if (whatPin == 5){
      led5();
      if(lengthButtonCounter == 3){
        whatPin = 0;   
      }   
    }
    if (whatPin == 6){
      led6();
      if(lengthButtonCounter == 2){
        whatPin = 0;   
      }   
    }
    if (whatPin == 7){
      led7();
      if(lengthButtonCounter == 1){
        whatPin = 0;   
      }   
    }
    if (whatPin == 8){
      led8();
      if(lengthButtonCounter == 0){
        whatPin = 0;   
      }   
    }
  }
}


void knightRider(){

  if (millis() - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = millis();

    whatPin = whatPin + 1;

    if (whatPin == 1){
      led1();
    }
    if (whatPin == 2){
      led2();
    }
    if (whatPin == 3){
      led3();
    }
    if (whatPin == 4){
      led4();
    }
    if (whatPin == 5){
      led5();
    }
    if (whatPin == 6){
      led6();
    }
    if (whatPin == 7){
      led7();
    }
    if (whatPin == 8){
      led8();
    }
    if (whatPin == 9){
      led7();
    }
    if (whatPin == 10){
      led6();
    }
    if (whatPin == 11){
      led5();
    }
    if (whatPin == 12){
      led4();
    }
    if (whatPin == 13){
      led3();
    }
    if (whatPin == 14){
      led2();
      whatPin = 0;
    }
  }
}

void crazy(){

  if (millis() - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = millis();

    whatPin = int(random(0,8));

    if(whatPin == previousWhatPin){
      whatPin++; 
      if(whatPin >= 8){
        whatPin = 1;
      }
    }

    if (whatPin == 0){
      led1();
      previousWhatPin = whatPin;
    }

    if (whatPin == 1){
      led2();
      previousWhatPin = whatPin;
    }

    if (whatPin == 2){
      led3();
      previousWhatPin = whatPin;
    }

    if (whatPin == 3){
      led4();
      previousWhatPin = whatPin;

    }
    if (whatPin == 4){
      led5();
      previousWhatPin = whatPin;
    }

    if (whatPin == 5){
      led6();
      previousWhatPin = whatPin;
    }

    if (whatPin == 6){
      led7();
      previousWhatPin = whatPin;
    }

    if (whatPin == 7){    
      led8();
      previousWhatPin = whatPin;
    }
  }
}

void allOff(){
  for(int i=0; i<ledCnt; i++)
  {
    digitalWrite(ledPins[i], LOW);
  } 
}
void led1(){
  digitalWrite(ledPins[1], LOW);
  digitalWrite(ledPins[2], LOW);
  digitalWrite(ledPins[3], LOW);
  digitalWrite(ledPins[4], LOW);
  digitalWrite(ledPins[5], LOW);
  digitalWrite(ledPins[6], LOW);
  digitalWrite(ledPins[7], LOW);
  digitalWrite(ledPins[0], HIGH);    
}
void led2(){
  digitalWrite(ledPins[0], LOW);
  digitalWrite(ledPins[1], LOW);
  digitalWrite(ledPins[2], LOW);
  digitalWrite(ledPins[3], LOW);
  digitalWrite(ledPins[4], LOW);
  digitalWrite(ledPins[5], LOW);
  digitalWrite(ledPins[6], LOW);
  digitalWrite(ledPins[7], LOW);
  digitalWrite(ledPins[1], HIGH);  
}
void led3(){
  digitalWrite(ledPins[0], LOW);
  digitalWrite(ledPins[1], LOW);
  digitalWrite(ledPins[3], LOW);
  digitalWrite(ledPins[4], LOW);
  digitalWrite(ledPins[5], LOW);
  digitalWrite(ledPins[6], LOW);
  digitalWrite(ledPins[7], LOW);
  digitalWrite(ledPins[2], HIGH); 
}
void led4(){
  digitalWrite(ledPins[0], LOW);
  digitalWrite(ledPins[1], LOW);
  digitalWrite(ledPins[2], LOW);
  digitalWrite(ledPins[4], LOW);
  digitalWrite(ledPins[5], LOW);
  digitalWrite(ledPins[6], LOW);
  digitalWrite(ledPins[7], LOW);
  digitalWrite(ledPins[3], HIGH); 
}
void led5(){
  digitalWrite(ledPins[0], LOW);
  digitalWrite(ledPins[1], LOW);
  digitalWrite(ledPins[2], LOW);
  digitalWrite(ledPins[3], LOW);
  digitalWrite(ledPins[5], LOW);
  digitalWrite(ledPins[6], LOW);
  digitalWrite(ledPins[7], LOW);
  digitalWrite(ledPins[4], HIGH); 
}
void led6(){
  digitalWrite(ledPins[0], LOW);
  digitalWrite(ledPins[1], LOW);
  digitalWrite(ledPins[2], LOW);
  digitalWrite(ledPins[3], LOW);
  digitalWrite(ledPins[4], LOW);
  digitalWrite(ledPins[6], LOW);
  digitalWrite(ledPins[7], LOW);
  digitalWrite(ledPins[5], HIGH); 
}
void led7(){
  digitalWrite(ledPins[0], LOW);
  digitalWrite(ledPins[1], LOW);
  digitalWrite(ledPins[2], LOW);
  digitalWrite(ledPins[3], LOW);
  digitalWrite(ledPins[4], LOW);
  digitalWrite(ledPins[5], LOW);
  digitalWrite(ledPins[7], LOW);
  digitalWrite(ledPins[6], HIGH);     
}
void led8(){
  digitalWrite(ledPins[0], LOW);
  digitalWrite(ledPins[1], LOW);
  digitalWrite(ledPins[2], LOW);
  digitalWrite(ledPins[3], LOW);
  digitalWrite(ledPins[4], LOW);
  digitalWrite(ledPins[5], LOW);
  digitalWrite(ledPins[6], LOW);
  digitalWrite(ledPins[7], HIGH);   
}

Regarding the part about buttons. It' generally better to change this:

  if (lengthButtonState != lastLengthButtonState){
    lastLengthButtonState = lengthButtonState;
    if (lengthButtonState == HIGH){
      allOff();
      lengthButtonCounter++;
      if(lengthButtonCounter >= 7){
        lengthButtonCounter = 0;
      }  
    }
  }

to this:

  if (lengthButtonState != lastLengthButtonState){
    if (lengthButtonState == HIGH){
      allOff();
      lengthButtonCounter++;
      if(lengthButtonCounter >= 7){
        lengthButtonCounter = 0;
      }  
    }
  }
[glow]  lastLengthButtonState = lengthButtonState;[/glow]

This way, the last button state is always set. Do the same for the mode button block.

The modeButtonPushCounter stuff could be put into a switch statement, for faster execution and easier to understand code.

Newbies write code like this:

    whatPin = whatPin + 1;

Experienced programmers write:

    whatPin++;

The led0() function replicates the code in allOff(), and turns ledPins[0] on. The led1() function replicates the code in allOff(), and turns lenPins[1] on. Ditto for led2(), led3(), etc.

I'm sure you (now) see some opportunity for optimization. First, remove all the duplicate functionality:

void led0()
{
   allOff();
   digitalWrite(ledPins[0], HIGH);
}

void led1()
{
   allOff();
   digitalWrite(ledPins[1], HIGH);
}

Then, you'll see that you could have just one function:

void ledOn(int pin)
{
   allOff();
   digitalWrite(ledPins[pin], HIGH);
}

Finally, to get to the root of your problem:

i don't understand why my mode button would work flawlessly, but the length button just makes stuff crash.

When you make these changes, you'll end up with less code to debug. A lot less. Then, the situation won't be so overwhelming. You may have even fixed the problem. If not, you'll need to take a deep breath, blow out all the frustration (totally understandable, by the way), and, then, calmly explain what is happening, what you want to happen, and, if it's not obvious, the difference between the two.