problems with leds in a big messy sketch

hi there i have a little problem i’m building a little gforce monitor with a arduino Mega and a s65 shield it has different modes its far away from being complete its just for learning for myself. anyway there is a serious problem with mode 2. the thing is mode two alone as a sketch works fine (with the int and setup stuff) but in this modesketch the arduino stops working if the blue(blau) led 3 and 4 are lit up about two or 3 times. like a bluescreen of death i can’t see any mistakes in the software and the wireing … well lots of wires but looks clean to me (will post photos if anybody want to see that ^^) . i don’t understand why it works alone but not in this sketch, any ideas?

#include <S65Display.h>
#include <RotaryEncoder.h>


// Leds:
int rot[] = { 52, 48, 44, 40, 36};      // von unten nach oben
int blau[] = {50, 46, 42, 38, 34};      // von unten nach oben
int num_rot = 5;
int num_blau = 5;
int ledtimer = 250;

// Schalter:            HIGH = gedrückt
int switch1 = 30;      // linker schalter
int switch2 = 32;      // rechter schalter
int button1;      // buttonzwischenspeicher1
int button2;      // buttonzwischenspeicher2
int button3;      // buttonzwischenspeicher3
int button4;      // buttonzwischenspeicher4
int buttonState1;      // buttonstatus1
int buttonState2;      // buttonstatus2
int Mode = 0;      // Modi zum durchschalten

// Accelerometer:
int xpin = 10;      // x-axis of the accelerometer
int ypin = 9;      // y-axis
int zpin = 8;      // z-axis
int xpos = 0;      // xposition
int ypos = 0;      // yposition
int zpos = 0;      // zposition
int xref = 0;      // xref
int yref = 0;      // yref
int zref = 0;      // zref

// Sharp Rangefinder:
int ir = 11;      // ir-pin
int range = 0;

// LCD und Encoder:
S65Display lcd;
RotaryEncoder encoder;
ISR(TIMER2_OVF_vect)
{TCNT2 -= 250;      // 1000 Hz
encoder.service();}

// Other:
int counter = 0;

void setup() {
// Ledpins als OUTPUT definieren
      int i = 0;
      for (i = 0; i < num_rot; i++)
      pinMode(rot[i], OUTPUT);
      for (i = 0; i < num_blau; i++)
      pinMode(blau[i], OUTPUT);

// Schalter als INPUT definieren
      pinMode(switch1, INPUT);
      pinMode(switch2, INPUT);

// LCD und Encoder
      lcd.init(4);
      encoder.init();
      TCCR2B  = (1<<CS22);      // clk=F_CPU/64
      TCNT2   = 0x00;
      TIMSK2 |= (1<<TOIE2);      // enable overflow interupt
      sei();      // interrupts on
      lcd.clear(RGB(0,0,0));      // clear screen

// Accelerometer      use something like this later:      xpos = map(analogRead(xpin), xpos2, xpos2+128, 88, 176);
      //read the sensor two times is important because the first reading is allways wrong
      xref = analogRead(xpin);
      delay (250);
      yref = analogRead(ypin);
      delay (250);
      zref = analogRead(zpin);
      delay (250);
      xref = analogRead(xpin);
      delay (250);
      yref = analogRead(ypin);
      delay (250);
      zref = analogRead(zpin);
      delay (250);

// Serial
      Serial.begin(9600);
}

void drawGTR(void){
      lcd.drawRect(88,0, 88, 132, RGB(96,115,255));
      lcd.drawRect(0, 66, 176, 66, RGB(96,115,255));
}


void drawGraph(void){
      lcd.drawTextPGM(5, 5, PSTR("Sideforce"), RGB(0, 0, 0), RGB(255, 255, 255)); //x
      lcd.drawTextPGM(5, 49, PSTR("Acceleration"), RGB(0, 0, 0), RGB(255, 255, 255)); //y
      lcd.drawTextPGM(5, 92, PSTR("Jump"), RGB(0, 0, 0), RGB(255, 255, 255)); //z
}

void loop(){

      int8_t move, press;

      move  = encoder.step();
      press = encoder.sw();
        if(move || press)
      {

      }


if(press == SW_PRESSEDLONG)
      {

      }

      if(move)
      {
      }

// press button 2 to reset refvariable
      button3 = digitalRead(switch2);
      delay(10);
      button4 = digitalRead(switch2);
            if (button3 == button4) {
      if (button3 != buttonState2) {
      if (button3 == LOW) {
            
                  xref = analogRead(xpin);
                  delay (50);
                  yref = analogRead(ypin);
                  delay (50);
                  zref = analogRead(zpin);
                  delay (50);
            }
            }
                  buttonState2 = button3;      // save the new state in our variable

            }
// end of button two function

// button 1 to switch trough modes
      button1 = digitalRead(switch1);      // read input value and store it in val
      delay(10);                         // 10 milliseconds is a good amount of time
      button2 = digitalRead(switch1);     // read the input again to check for bounces
      if (button1 == button2) {                 // make sure we got 2 consistant readings!
      if (button1 != buttonState1) {          // the button state has changed!
      if (button1 == LOW) {                // check if the button is pressed

      if (Mode == 0) {
      Mode = 1;
      } else {
      if (Mode == 1) {
      Mode = 2;
      } else {
      if (Mode == 2) {
      Mode = 3;
      } else {
      if (Mode == 3) {
      Mode = 4;
      } else {
      if (Mode == 4) {
      Mode = 0;
      }
      }
      }
      }
      }
      }
      }
      buttonState1 = button1;
      }
// end of button 1 function

// Modes
      if (Mode == 0) {      //Mode 0 complete
      counter = counter++;
      if (counter == 1) {
      lcd.clear(RGB(0,0,0));}
            drawGTR();
            xpos = map(analogRead(xpin), xref, xref+256, 88, 176);
            xpos = map(xpos, 0, 176, 176, 0);
            ypos = map(analogRead(ypin), yref, yref+256, 66, 132);
            zpos = map(analogRead(zpin), zref, zref+256, 100, 200);
            lcd.drawRect(xpos-2, ypos-2, xpos +2, ypos +2, RGB(255, 255-zpos, 255-zpos));
            delay(100);
            lcd.drawRect(xpos-2, ypos-2, xpos +2, ypos +2, RGB(0,0,0));
            if(press == SW_PRESSED){
                  lcd.clear(RGB(0,0,0));
                  drawGTR();
                  }
      }


      if (Mode == 1) {      //Mode 1 clear lcd dosn't work think harder
            counter = counter++;
            if (counter == 3) {
            lcd.clear(RGB(0,0,0));
            drawGraph();}
            xpos = map(analogRead(xpin), xref, xref+256, 88, 176);
            lcd.drawRect(0, 32, xpos, 44, RGB(0,255,0));
            lcd.drawRect(xpos, 32, 176, 44, RGB(0,0,0));

            ypos = map(analogRead(ypin), yref, yref+256, 88, 176);
            lcd.drawRect(0, 76, ypos, 88, RGB(0,0,255));
            lcd.drawRect(ypos, 76, 176, 88, RGB(0,0,0));

            zpos = map(analogRead(zpin), zref, zref+256, 88, 176);
            lcd.drawRect(0, 120, zpos, 132, RGB(255,0,0));
            lcd.drawRect(zpos, 120, 176, 132, RGB(0,0,0));
            delay(100);

            if(press == SW_PRESSED){
                  lcd.clear(RGB(255,255,255));
                  drawGraph();
                  }
      }

// mode 2
      if (Mode == 2) {
            xpos = map(analogRead(xpin), xref, xref+100, 0, 5);
            if (xpos == 1){digitalWrite(blau[4], HIGH);}
            if (xpos == 2){digitalWrite(blau[3], HIGH);}
            if (xpos == 3){digitalWrite(blau[2], HIGH);}
            if (xpos == 4){digitalWrite(blau[1], HIGH);}
            if (xpos == 5){digitalWrite(blau[0], HIGH);}

            xpos = map(analogRead(xpin), xref, xref+100, 0, 5);
            if (xpos == -1){digitalWrite(rot[4], HIGH);}
            if (xpos == -2){digitalWrite(rot[3], HIGH); }
            if (xpos == -3){digitalWrite(rot[2], HIGH);}
            if (xpos == -4){digitalWrite(rot[1], HIGH);}
            if (xpos == -5){digitalWrite(rot[0], HIGH);}
      
      delay (100);
      
      int i = 0;
      for (i = 0; i < num_rot; i++)
      {digitalWrite(rot[i], LOW);};

      for (i = 0; i < num_blau; i++)
      {digitalWrite(blau[i], LOW);};
      }

// mode 3
      if (Mode == 3) {      // add capacitors to input to much noise when ir is attached
                  drawGTR();
                  range = map(analogRead(ir),0, 1024, 0, 176);
                  delay (50);
            lcd.drawRect(0, 32, range, 44, RGB(0,255,0));
            lcd.drawRect(range, 32, 176, 44, RGB(0,0,0));
            xpos = map(analogRead(xpin), xref, xref+256, 88, 176);
            xpos = map(xpos, 0, 176, 176, 0);
            ypos = map(analogRead(ypin), yref, yref+256, 66, 132);
            zpos = map(analogRead(zpin), zref, zref+256, 100, 200);
            lcd.drawRect(xpos-2, ypos-2, xpos +2, ypos +2, RGB(255, 255-zpos, 255-zpos));
            delay(100);
            lcd.drawRect(xpos-2, ypos-2, xpos +2, ypos +2, RGB(0,0,0));
            if(press == SW_PRESSED){
                  lcd.clear(RGB(0,0,0));
                  drawGTR();
                  }

      }


      if (Mode == 4) {
      
      }
}