4 Digit 7 Segment LED Display with Shift Out Registers

Hi everyone,

As part of a project we need to connect an LED display with shift out registers and buttons to an Arduino. We need to be able to switch between the digits, but it needs to 'remember' what is shown on the other digits. I guess we need to do something with the clock, but I honestly have no idea what the best way to do that is. Currently you can switch between the digits with buttons, but it takes the shown number to the next digit.

This is our current code:

int latchPin = 8;
int clockPin = 12;
int dataPin = 13;
int button1 = 2; //down
int button2 = 3; //up
int button3 = 4; //digit left (down)
int button4 = 5; //digit right (up)
int led = 0;
int dig[4] = {7,11,13,14};
int counter = 0;


void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(2,INPUT_PULLUP);
  pinMode(3,INPUT_PULLUP);
  pinMode(4,INPUT_PULLUP);
  pinMode(5,INPUT_PULLUP);
  
  Serial.begin(9600);
}

void loop() {
  if(digitalRead(button1) == LOW && led != 0){led--;}
  if(digitalRead(button2) == LOW && led != 9){led++;}
  if(digitalRead(button3) == LOW && counter != 0){counter--;}
  if(digitalRead(button4) == LOW && counter != 3){counter++;}
  writeToDisp(led, dig[counter]);
  delay(200);
}


void writeToDisp(int number, int digit){
  digitalWrite(latchPin, LOW);
  switch(number){
    case 0:
      shiftOut(dataPin, clockPin, MSBFIRST, digit);  //digit power
      shiftOut(dataPin, clockPin, MSBFIRST, 215);    //the number 0 is shown
      break;
    case 1:
      shiftOut(dataPin, clockPin, MSBFIRST, digit);  //digit power
      shiftOut(dataPin, clockPin, MSBFIRST, 20);     //the number 1 is shown
      break;
    case 2:
      shiftOut(dataPin, clockPin, MSBFIRST, digit);  //digit power
      shiftOut(dataPin, clockPin, MSBFIRST, 205);    //the number 2 is shown
      break;
    case 3:
      shiftOut(dataPin, clockPin, MSBFIRST, digit); //digit power
      shiftOut(dataPin, clockPin, MSBFIRST, 93);    //the number 3 is shown
      break;
    case 4:
      shiftOut(dataPin, clockPin, MSBFIRST, digit); //digit power
      shiftOut(dataPin, clockPin, MSBFIRST, 30);    //the number 4 is shown
      break;
    case 5:
      shiftOut(dataPin, clockPin, MSBFIRST, digit); //digit power
      shiftOut(dataPin, clockPin, MSBFIRST, 91);    //the number 5 is shown
      break;
    case 6:
      shiftOut(dataPin, clockPin, MSBFIRST, digit); //digit power
      shiftOut(dataPin, clockPin, MSBFIRST, 251);   //the number 6 is shown
      break;
    case 7:
      shiftOut(dataPin, clockPin, MSBFIRST, digit); //digit power
      shiftOut(dataPin, clockPin, MSBFIRST, 21);    //the number 7 is shown
      break;
    case 8:
      shiftOut(dataPin, clockPin, MSBFIRST, digit); //digit power
      shiftOut(dataPin, clockPin, MSBFIRST, 223);   //the number 8 is shown
      break;
    case 9:
      shiftOut(dataPin, clockPin, MSBFIRST, digit); //digit power
      shiftOut(dataPin, clockPin, MSBFIRST, 127);   //the number 9 is shown
      
  }
  digitalWrite(latchPin, HIGH);
}