LEDs turning off - not supposed to!

Ok, here is a code segment. My leds are turning off randomly in this code (they should be dimming slightly). My other code works fine on them. It is just this section.

Using a Arduino Nano for the controller.

Initially though leds might be over heating but others (same spec) are staying on constantly.

Any ideas?

This is in the main loop.

for (int y = 0; y < 1000; y++) {

int x = random(1,6);
Serial.print(y);
Serial.print(" ");
Serial.println(x);
switch(x)
{
case 1:
analogWrite(led1, 220);
delay(750);
analogWrite(led1, 256);
case 2:
analogWrite(led2, 220);
delay(750);
analogWrite(led2, 256);
case 3:
analogWrite(led3, 220);
delay(750);
analogWrite(led3, 256);
case 4:
analogWrite(led4, 220);
delay(750);
analogWrite(led4, 256);
case 5:
analogWrite(led5, 220);
delay(750);
analogWrite(led5, 256);
case 6:
analogWrite(led6, 220);
delay(750);
analogWrite(led6, 256);
}
delay(10000);
}

For PWM PINS, the duty cycle: between 0 (always off) and 255 (always on).

To get help, you must show us your “complete” sketch. Attach your code using the </> icon on the left side of the posting menu.

Sorry, here is the full code:

const int led1=3;
const int led2=5;
const int led3=6;
const int led4=9;
const int led5=10;
const int led6=11;

const int tran=12;

const int BUTTON=2;

boolean lastButton = LOW;
boolean currentButton = LOW;

void setup() {

  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT);
  pinMode (led3, OUTPUT);
  pinMode (led4, OUTPUT);
  pinMode (led5, OUTPUT);
  pinMode (led6, OUTPUT);
  pinMode (BUTTON, INPUT);
  pinMode (tran, OUTPUT); 

  Serial.begin(9600);
  
}

void stage1() {
  digitalWrite(tran, HIGH);
  for (int i=0; i<64; i++)
  {  
     analogWrite(led1, i);
     analogWrite(led2, i);
     analogWrite(led3, i);
     analogWrite(led4, i);
     analogWrite(led5, i);
     analogWrite(led6, i);

     int x = random(1,6);
     delay(100);
     switch(x)
      {
       case 1:
            analogWrite(led1, i*0.5);
       case 2:
            analogWrite(led2, i*0.5);
        case 3:
            analogWrite(led3, i*0.5);
        case 4:     
            analogWrite(led4, i*0.5);
        case 5:     
            analogWrite(led5, i*0.5);
        case 6:     
            analogWrite(led6, i*0.5);
      }
    delay(100);
 
    switch(x)
      {
        case 1:
            analogWrite(led1, i);
        case 2:
            analogWrite(led2, i);
        case 3:
            analogWrite(led3, i);
        case 4:
            analogWrite(led4, i);
        case 5:     
            analogWrite(led5, i);
        case 6:     
            analogWrite(led6, i);
      }
      Serial.print("section 1: ");
      Serial.println(i);
  }
delay(100);
}

void stage2() {
for (int i=64; i<128; i++)
  {
     analogWrite(led1, i);
     analogWrite(led2, i);
     analogWrite(led3, i);
     analogWrite(led4, i);
     analogWrite(led5, i);
     analogWrite(led6, i);

     delay(100);
    int x = random(1,6);

     switch(x)
      {
       case 1:
            analogWrite(led1, i*0.63);
       case 2:
            analogWrite(led2, i*0.63);
        case 3:
            analogWrite(led3, i*0.63);
        case 4:     
            analogWrite(led4, i*0.63);
        case 5:     
            analogWrite(led5, i*0.63);
        case 6:     
            analogWrite(led6, i*0.63);
      }
     delay(100);
    switch(x)
      {
        case 1:
            analogWrite(led1, i);
        case 2:
            analogWrite(led2, i);
        case 3:
            analogWrite(led3, i);
        case 4:
            analogWrite(led4, i);
        case 5:     
            analogWrite(led5, i);
        case 6:     
            analogWrite(led6, i);
      }
      Serial.print("section 2: ");
      Serial.println(i);
  }
delay(100);  
}

void stage3() {
  for (int i=128; i<192; i++)
  {
     analogWrite(led1, i);
     analogWrite(led2, i);
     analogWrite(led3, i);
     analogWrite(led4, i);
     analogWrite(led5, i);
     analogWrite(led6, i);

    delay(100);
    int x = random(1,6);

     switch(x)
      {
       case 1:
            analogWrite(led1, i*0.76);
       case 2:
            analogWrite(led2, i*0.76);
        case 3:
            analogWrite(led3, i*0.76);
        case 4:     
            analogWrite(led4, i*0.76);
         case 5:     
            analogWrite(led5, i*0.76);
        case 6:     
            analogWrite(led6, i*0.76);
      }
     delay(100);
    switch(x)
      {
        case 1:
            analogWrite(led1, i);
        case 2:
            analogWrite(led2, i);
        case 3:
            analogWrite(led3, i);
        case 4:
            analogWrite(led4, i);
        case 5:     
            analogWrite(led5, i);
        case 6:     
            analogWrite(led6, i);
      }
      Serial.print("section 3: ");
      Serial.println(i);
  }
delay(100); 
}

void stage4() {
  
for (int i=192; i<256; i++)
  {
     analogWrite(led1, i);
     analogWrite(led2, i);
     analogWrite(led3, i);
     analogWrite(led4, i);
     analogWrite(led5, i);
     analogWrite(led6, i);
     delay(100); 
    int x = random(1,6);

     switch(x)
      {
       case 1:
            analogWrite(led1, i*0.89);
       case 2:
            analogWrite(led2, i*0.89);
        case 3:
            analogWrite(led3, i*0.89);
        case 4:     
            analogWrite(led4, i*0.89);
        case 5:     
            analogWrite(led5, i*0.89);
        case 6:     
            analogWrite(led6, i*0.89);
      }
     delay(100);
    switch(x)
      {
        case 1:
            analogWrite(led1, i);
        case 2:
            analogWrite(led2, i);
        case 3:
            analogWrite(led3, i);
        case 4:
            analogWrite(led4, i);
        case 5:     
            analogWrite(led5, i);
        case 6:     
            analogWrite(led6, i);
      }
      Serial.print("section 4: ");
      Serial.println(i);
  }
  delay(100);
}


void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Main");
  stage1();
  stage2();
  stage3();
  stage4();

  for (int y = 0; y < 1000; y++) {
   
    int x = random(0,6)+1;
        Serial.print(y);
        Serial.print("     ");
      Serial.println(x);
     switch(x)
      {
       case 1:
            analogWrite(led1, 220);
            delay(750);
            analogWrite(led1, 256);
       case 2:
            analogWrite(led2, 220);
            delay(750);
            analogWrite(led2, 256);
        case 3:
            analogWrite(led3, 220);
            delay(750);
            analogWrite(led3, 256);
        case 4:     
            analogWrite(led4, 220);
            delay(750);
            analogWrite(led4, 256);
        case 5:     
            analogWrite(led5, 220);
            delay(750);
            analogWrite(led5, 256);
        case 6:     
            analogWrite(led6, 220);
            delay(750);
            analogWrite(led6, 256);
      }
      delay(100);
  }  

analogWrite(led1, 0);
analogWrite(led2, 0);
analogWrite(led3, 0);
analogWrite(led4, 0);
analogWrite(led5, 0);
analogWrite(led6, 0);

}

an update:

Watching code on console. The LEDs are turning off on this command: analogWrite(led2, 220) instead of dimming by a bit.

What does this line do?

analogWrite(led1, 256);

.

That is making the LED come back on, but then turning right off again after the delay.

What is the range of X?

analogWrite(led1, X);

In the main loop - in switch statement, x should be 1 through 6

But where do you see analogWrite(led1, X) ?

analogWrite(led1, X);
The range of X is: an integer from 0 to 255. You have 256.
analogWrite(led1, 256);

Thanks!, I could have looked at that for weeks and not seen it. Used to programming with values going from 1 not 0.

Also:
analogWrite(led6, i*0.63);

You do realize, the second argument is to be an INTEGER, not a FLOAT.

Yes, but it get close enough and makes the flicker ramp up like I want.

I'm using it for engines on a star wars star destroyer to make it look like they are coming up to full power.

Don't let it get to full power, it could explode!

You do realise don't you that the code, if written properly, reduces that case statement to just three lines?
The same is true of the other very much longer code you posted in another thread.