Atmega328 and 4Digit 7 Segment ghost blinking! I hooked up 4 7Seg leds (CC) with NPN transistors on the cathode of each digit. I am using 74HC595 shift register connected in the circuit in a pretty common fashion. The code I am running is the basic scanning code for the 7seg. The problem is that I see the scanned numbers on other LED digits too. Attached is the image. I call them &quot;ghosts&quot;. The circuit I am using has an Atmega328 with an internal 8MHz Osc. The resistors on the segments are 220Ohm and 4 BC547's on the cathodes of the digits with 1kOhm resistors on their base.

below is the code:
void loop() {
 
      cathode_high(); // blank the screen
  
      break_number(number);
      
      display_number();
     delay(1);

    
}

void break_number(int num) { // seperate the input number into 4 single digits

  first_digit = num / 1000;
  digits[0] = first_digit;  

  int first_left = num - (first_digit * 1000);
  second_digit = first_left / 100; 
  digits[1] = second_digit;
  int second_left = first_left - (second_digit * 100); 
  third_digit = second_left / 10; 
  digits[2] = third_digit; 
  fourth_digit = second_left - (third_digit * 10);
  digits[3] = fourth_digit;
  
  
}

void display_number() { //scanning
   
  cathode_high(); 
  digitalWrite(latch, LOW); 
  shiftOut(data, clk, LSBFIRST, numbers[digits[count]]); 
  digitalWrite(CAS[count], HIGH); 
  digitalWrite(latch, HIGH); 
  count++; 
  if (count == 4) {
    count = 0;
  }
}

void cathode_high() { //turn off all 4 digit
  digitalWrite(CA_1, LOW);
  digitalWrite(CA_2, LOW);
  digitalWrite(CA_3, LOW);
  digitalWrite(CA_4, LOW);
}
Any help would be highly appreciated. Thanx in advance!
You change cathodes (digits) before latching in the new data. So for a spit second the data for the previous digits is shown on the current digit.
Swapping digitalWrite(CAS[count], HIGH); and digitalWrite(latch, HIGH); should fix that.