How to clear up leds on matrix 8 x 8_2x_shift_registers

everything is fine one problem is
How would you do to clear up the matrix 8 x 8 on 2 x shift registers 595. If I press switch case of 1. I am not sure how to set up to rid off the old leds replace to blank led as a function for the next case of 2.

the switch case 1 is a clock diagram.

the switch case 2 is a Random LEDs lighting down.

I am trying to put the function as blankLed(); inside the case 1. It refused clear the leds for the next one.

one thing i dont like wait for the frames 11 to clear up the whole led. to do next one.

How would you set up any frame to clear up ?

// switch case project 2
// Project 20
#include <TimerOne.h>

int latchPin = 8; //Pin connected to Pin 12 of 74HC595 (Latch) RED JUMPER CONNECT TO MIDDLE

int clockPin = 12; //Pin connected to Pin 11 of 74HC595 (Clock)BROWN JUMMPER CONNT TO RIGHT
int dataPin = 11; //Pin connected to Pin 14 of 74HC595 (Data) BLACK JUMPER CONNECT TO LEFT
int led13 = 13;
int buttonPin = 7;
int state = 0; 
int counter = 0;
byte frame = 0;  // variable to store the current frame being displayed


int LEDclear[8][8] = {   
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0}     
};  
byte led[11][11] = {    // the first array is bottom, the last array is top 
                      {1, 56, 92, 158, 158, 130, 68, 56}, // 11 frames of an animation
                      {2, 56, 124, 186, 146, 130, 68, 56},
                      {4, 56, 116, 242, 242, 130, 68, 56},
                      {8, 56, 68, 226, 242, 226, 68, 56},
                      {16, 56, 68, 130, 242, 242, 116, 56},
                      {32, 56, 68, 130, 146, 186, 124, 56},
                      {64, 56, 68, 130, 158, 158, 92, 56},
                      {128, 56, 68, 142, 158, 142, 68, 56},
                      {1,255,1,1,1,56,255,254},
                      {16,56,124,254,254,254,238,68},
                      {0, 0, 0, 0, 0, 0, 0, 0}
                   
                  };
int LED2[8][8] = {   
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0},
                      {0, 0, 0, 0, 0, 0, 0, 0}      
};                      

void setup() {
        pinMode(latchPin, OUTPUT);  // set the 3 digital pins to outputs
        pinMode(clockPin, OUTPUT);
        pinMode(dataPin, OUTPUT);
        pinMode(led13, OUTPUT); // 13 LED 

        pinMode(buttonPin, INPUT);//this time we will set the pin as INPUT
        Serial.begin(9600);//initialize Serial connection

        Timer1.initialize(10000); // set a timer of length 10000 microseconds 
        Timer1.attachInterrupt(screenUpdate); // attach the screenUpdate function
}

void loop() {
  switch(state){
    case 1:
      Serial.println("    Pressed");
        for (int i=0; i<11; i++) { // loop through all 11 frames of the animation
                for (int j=0; j<11; j++) { // loop through the 8 rows per frame
                        led[i][j]; // = led[i][j] << 1 | led[i][j] >> 7; // bitwise rotation , repeat back begining to left side from right side.   
                  }
        }
        frame++; // go to the next frame in the animation
        if (frame > 10) 
        { 
          frame = 0;
        } // make sure we go back to frame 0 once past 7
        delay(500); // wait a bit between frames     
        if(digitalRead(buttonPin) == HIGH ){
//          blankLED(); wont work
//        led[11][10]; wont work 
          state += 1;
          delay(100);
      }
       break;
    case 2:
      Serial.println("    blinking 1000");
// www.insidegadgets.com/2010/11/07/fun-with-8x8-led-matrix/
// LED Matrix - Random LEDs lighting up
      LED2[random(8)][random(8)] = 1;
      if (counter > 200) {
        blankLED();
        counter = 0;
      }      
      lightLED();
      counter++;
      
      if(digitalRead(buttonPin) == HIGH ){
              state += 1;
              blankLED();
              delay(100);
      }      
        break;
     default:
//      Serial.println("blinking 500 millis");
      Serial.println("press a button please");
      digitalWrite(led13, HIGH);   // turn the LED on (HIGH is the voltage level)
        delay(100);               // wait for a second
      digitalWrite(led13, LOW);    // turn the LED off by making the voltage LOW
        delay(100);
     // press the button increment case swtich
         if(digitalRead(buttonPin) == HIGH ){
          state += 1;
          Serial.println("The case would be number" );
          }
  }// end switch 
  if(state == 3){
    state = 0;
  }
}

void screenUpdate() { // function to display image
        byte row = B10000000; // row 1
        for (byte k = 0; k < 9; k++) {
          digitalWrite(latchPin, LOW); // open latch ready to receive data

                shiftIt(~led[frame][k] ); // LED array (inverted)
                shiftIt(row); // row binary number

                // Close the latch, sending the data in the registers out to the matrix
                digitalWrite(latchPin, HIGH);
                row = row >> 1; // bitshift right
        }
}

void shiftIt(byte dataOut) {
        // Shift out 8 bits LSB first, on rising edge of clock

        boolean pinState; 

        //clear shift register read for sending data
        digitalWrite(dataPin, LOW);

        // for each bit in dataOut send out a bit
        for (int i=0; i<8; i++)  {
                //set clockPin to LOW prior to sending bit
                digitalWrite(clockPin, LOW);

                // if the value of DataOut and (logical AND) a bitmask
                // are true, set pinState to 1 (HIGH)
                if ( dataOut & (1<<i) ) {
                        pinState = HIGH;
                }
                else {
                        pinState = LOW;
                }

                //sets dataPin to HIGH or LOW depending on pinState
                digitalWrite(dataPin, pinState);
                //send bit out on rising edge of clock 
                digitalWrite(clockPin, HIGH);
                digitalWrite(dataPin, LOW);
        }

digitalWrite(clockPin, LOW); //stop shifting
}

void blankLED() {
  int x = 0;
  int y = 0;
  for (x = 0; x < 8; x++) {
    for (y = 0; y < 8; y ++) {
      LED2[x][y] = 0;
    }
  }
}

void lightLED() {
  byte columnbitsToSend = 0;
  byte rowbitsToSend = 0;
  
  int x = 0;
  int y = 0;
  for (x = 0; x < 8; x++) {
    columnbitsToSend = 0;
    rowbitsToSend = 0;
      
    for (y = 0; y < 8; y ++) {
      if (LED2[x][y] == 1) {
        bitWrite(columnbitsToSend, y, HIGH);
      } 
    }
    
    digitalWrite(latchPin, LOW);
    bitWrite(rowbitsToSend, x, HIGH);
    shiftOut(dataPin, clockPin, MSBFIRST, columnbitsToSend);
    shiftOut(dataPin, clockPin, MSBFIRST, rowbitsToSend);
    digitalWrite(latchPin, HIGH);   
    delay(2);
  }
}

All that the blankLed() function does is to set all the entries in the LED2 array to zero. You need to call the lightLed() function afterwards to actually write the array to the LEDs.

A couple of observations. You already have an array, LEDclear, that is full of zeros but you don't use it so it is just wasting space. Further, your arrays do not need to be ints they could be bytes which will also save space.

A couple of observations. You already have an array, LEDclear, that is full of zeros but you don't use it so it is just wasting space. Further, your arrays do not need to be ints they could be bytes which will also save space.

Thanks for the heading me up. I just modified code a lit bit.

the video is demo for a minute.

https://www.youtube.com/watch?v=NQz0LD9C18A

the video was before the solved the code see as below. I did not added "frame = 0"

if(digitalRead(buttonPin) == HIGH ){
          frame = 0; // clear up the led. this is a solved. target to the frame 0. 
          state += 1;
          delay(100);
        }

How would you do storage in variable if I press the button as HIGH and change to the case 2. sometime I missed the press because of delay limited time.