Hi, I am trying to create a game with my Arduino Uno, with an 8 digit 7 segment MAX7219 display that shows the score at the end of the game, followed by the high score. I have created a function called updateShotCounter, and call it twice within the same subroutine. The problem, is that it only updates the display the once, and even after a delay, when function is called again to display the highscore, it doesn't update.
Subroutine where I display game score and high score.
This is my function to update scores to 8 digit display
void updateShotCounter(int shotcounter) {
int dig2 = 1;
int digCnt2 = 0;
// if number is greater than zero
if (shotcounter > 0) {
// count # of digits
while (shotcounter >= dig2) {
dig2 *= 10;
digCnt2++;
} // while
for (int d2 = 0; d2 < digCnt2; d2++) {
// wite this digit
lc.setDigit(0, d2+4, byte(shotcounter % 10), false);
// writing from right to left
shotcounter /= 10;
} // while
}
}
looks like updateTimer() attempts to call printNum() only every second, but it looks like printNum() has several delays and take > 5 seconds to complete so that printNum() is called every time updateTimer() is called
try adding a delay after displaying highScore to see if that is the problem and take another look at the time flow of your code
Thanks, that did the trick! I went into my void loop(), and added an if statement to only update the score via updateShotCounter() if game hasn't ended.
Cheers!