Count up timer not displaying properly

Hi All

I am trying to make a football scoreboard with 8 seven segment displays. Two displays for home and away score and four displays for a timer.

I will be controlling the scoreboard using an LCD keypad shield. So far I have managed to figure out the code that lets the user set the game length and control home and away score through the LCD keypad shield screen and buttons.

I am now stuck with timer code. The problem I am having is that the function that runs the for loop based on the difference between start_time and end_time variables is not working properly. Using the serial for debugging has not helped much as the count up timer seems to work fine with the serial. The seven segments however do not get updated each second. They rather get updated once with the maximum value of start_time variable and remain static.

Here is my code so far:

#define ShiftReg_LatchPin  51
#define ShiftReg_ClockPin  49
#define ShiftReg_DataPin   47

#define DisplayCount 8
byte g_digits [10];
int g_numberToDisplay = 0;
byte g_registerArray [DisplayCount]; 

long unsigned int start_time;
long unsigned int end_time;
int Tens;
int Mins;
int Secs;

int mm1;
int mm2;
int ss1;
int ss2;

int home_score = 0;
int away_score = 0;

void setup()
{
Serial.begin(9600);

start_time = 0;
end_time = 30;

pinMode (ShiftReg_LatchPin, OUTPUT);
pinMode (ShiftReg_ClockPin, OUTPUT);
pinMode (ShiftReg_DataPin, OUTPUT);
 
 g_digits [0] = B01111110;  //0   Bxxxxxxxx
 g_digits [1] = B01001000;  //1   BdCDEBAFG
 g_digits [2] = B00111101;  //2   B number order
 g_digits [3] = B01101101;  //3       --A--
 g_digits [4] = B01001011;  //4    F |     | B
 g_digits [5] = B01100111;  //5      |--G--|
 g_digits [6] = B01110111;  //6    E |     | C
 g_digits [7] = B01001100;  //7       --D-- o = d
 g_digits [8] = B01111111;  //8
 g_digits [9] = B01101111;  //9
}

void loop(){
BuildSendStringForLEDs();
sendSerialData(DisplayCount,g_registerArray);
}

void  BuildSendStringForLEDs(){
  for(start_time = 0; start_time < end_time; start_time++){
    Mins = start_time / 60;
    Secs = (start_time - (Mins * 60));
    Tens = Mins / 10;
    mm1 = Tens;
    mm2 = Mins - (Tens * 10);
    g_registerArray[3] = g_digits [mm1];
    g_registerArray[2] = g_digits [mm2];
  
    Tens = Secs / 10;
    ss1 = Tens;
    ss2 = Secs - (Tens * 10);
    g_registerArray[1] = g_digits [ss1];
    g_registerArray[0] = g_digits [ss2];
  
    Serial.print(mm1);
    Serial.print(mm2);
    Serial.print(":");
    Serial.print(ss1);  
    Serial.println(ss2);

 delay(1000);
 }
}

void sendSerialData (byte registerCount, byte *pValueArray){
  digitalWrite (ShiftReg_LatchPin, LOW);
  for (byte reg = 0; reg < DisplayCount; reg++){
    for (byte bitMask = 128; bitMask > 0; bitMask >>= 1){
      digitalWrite (ShiftReg_ClockPin, LOW);
      if ((pValueArray[reg] & bitMask) == bitMask){
        digitalWrite (ShiftReg_DataPin, HIGH );
      }
      else{
        digitalWrite (ShiftReg_DataPin, LOW );
      }
      digitalWrite (ShiftReg_ClockPin, HIGH);
    }
  }
  digitalWrite (ShiftReg_LatchPin, HIGH);
}

You are counting up to “end_time” inside “BuildSendStringForLEDs()” and then calling “sendSerialData()” once.

Either move “for(start_time = 0; start_time < end_time; start_time++)” into loop() or put the call to “sendSerialData()” inside the for-loop, like the debug output is.

Thanks a lot for your prompt reply. The solution suggested worked perfectly. I am now calling the sendSerialData inside the BuildSendStringForLEDs function after the serial.print commands.