I'm trying to put together a countdown clock using a 4 digit 7 Segment LED and Max7219 IC. I'm basing my design and the code on this one I found on YouTube: https://www.youtube.com/watch?v=FVcnsAxUx0w .

I've modified my display to countdown like a hockey or basketball scoreboard but I have two questions right now. My countdown starts with two minutes digits and two seconds digits in a 00:00 format. Once it gets below 10 min the first digit goes dark and it is a 0:00 format. Once it gets below a minute it is a seconds and tenths of seconds format at 00.0. Once it gets below 10 seconds it is a minutes and tenths of seconds format at 0.0 until zero. My first issue is that for a second from the transition from 10:00 min to 9:59 min there is a flash of a zero in the first digit (the one that will go dark). The same thing happens for a 10th of a second from 10.0 to 9.9 seconds. Any idea how I can get rid of that?

I'm also trying to figure out how to pause and resume the timer. I've tried to incorporate a switch and a pause for a period of time but my button is not responsive.

Actually I no longer have the display of 09:59 but there is still an image of the zero flashing for a brief time.

I'm thinking stopping and starting the clock should be so simple but I can't get any of my attempts to work.

Also my ultimate goal is to integrate displays to show scoring, periods, and sound files to start and stop play. My current code takes 4672 bytes. I'm afraid I might run out of memory for the sketch. Any suggestions on how to simplify what I have at this point?

In delaySet(), you have an infinite loop with no way to exit it. countDown() should NOT be called from delaySet(). Instead, where the call to countDown() is should be a break statement. That will exit the infinite loop in delaySet(), allowing delaySet() to end, and control to return to loop.

That is where/when you should call countDown().

The countDown() function contains another infinite loop. There is no way that I can see (admittedly, the code structure makes it hard to see, so I might have missed it) to stop the "timer". There is code to suspend the "timer" for 10 seconds, but it's hard to see where that fits in the while loop.

1) displaying from a buffer: run this part from a timer interrupt so it is done transparently. All you need is to stuff font information into the buffer;2) time keeping: put this in another timer interrupt to keep track of count-down time.3) processing: do this in the main loop. Process buttons, process time keeping and convert it to the right font info into the display buffer. For example, if the time is less than 10 minutes, put 'blank' into the 1st char of the buffer, '8' into the 2nd char of the buffer, '3' into the 3rd and '2' into the fourth to display ' 8:32'. To pause, you just need to pause the time keeping function.

First of all, I cribbed this code from someone else so I can't take credit. However, I can assume blame for aggravating any of its weaknesses. Basically I took a countdown sketch and attempted to shoehorn my application into it. I'm new to programming and electronics but I have above average technical skills so I'm hoping to tackle this with guidance.

In delaySet(), you have an infinite loop with no way to exit it. countDown() should NOT be called from delaySet(). Instead, where the call to countDown() is should be a break statement. That will exit the infinite loop in delaySet(), allowing delaySet() to end, and control to return to loop.

I am familliar with the principals of break statements but have not written any. I will try my hand at putting one together and give it another shot.

The countDown() function contains another infinite loop. There is no way that I can see (admittedly, the code structure makes it hard to see, so I might have missed it) to stop the "timer". There is code to suspend the "timer" for 10 seconds, but it's hard to see where that fits in the while loop.

These infinite loops are likely preventing my attempts to stop the timer. I just pasted the code in the sketch at various places and crossed my fingers (this should be an indication of the programming expertise you are dealing with).

Dhenry,I have to do some research to understand your suggestions. Are there example sketches you could point me to that illustrate these principals? I'm sure I've seen some but I'm still learning to understand code.

Dhenry,I have to do some research to understand your suggestions. Are there example sketches you could point me to that illustrate these principals? I'm sure I've seen some but I'm still learning to understand code.

Dhenry is quite keen on using interrupts, but in my opinion they are not needed here and just make the solution needlessly complicated.

All you need is the technique shown in 'blink without delay' to trigger some clock processing at regular intervals. Define global variable holding the hours, minutes, seconds, tenths remaining. Your clock processing code decrements the timer values and displays them.

If you want a button to pause and resume the countdown then you just need to add a global flag indicating whether the clock is currently running, and poll the switch input to decide when to change it between 'running' and 'paused'. In your clock processing code you skip the 'decrement and redisplay' code if the clock is 'paused'. This is all straight forward.

I only provide help via the forum - please do not contact me for private consultancy.

I did the same with a MAX7221 for my fencing scoring machine.I check every 1/4 second to make the colon flash on/off, and every 4 checks update the seconds and other digits as needed.The rest of the time I am checking for button presses, RF commands, etc.Easy to change that for 1/10 second checks, still plenty of time to read slow (by comparison) button presses.

I've been experimenting with breaks and my while loops and cleaned up my sketch a bit but it is very likely my timer and display functions could be simplified further. As I mentioned above I have five timer display situations depending on the time elapsed. Instead of running a bunch of while statements would a switch statement be more clean and efficient?

I just need to figure out how to do FUNCTION X and integrate buttons and other controls. I'd prefer to use the Arduino's internal clock rather than an external clock though.

A guy who made a similar scoreboard used a CD4021 shift register and an external clock for various controls such as time out, reset, advancing score and such. I've steered away from his design because his sketch was hard to understand at my current stage. Should I lean in that direction?

if (100mS elapsed){// do the digit changing & display updating stuff via MAX7219 SPI.transfer commands// }// rest of the time, read buttons, do other stuff - there is a lot to processing time left to do that stuff.

Lots of things will happen when time is not running - incrementing the score, the period counter, buzzing the score indicator, etc.

I don't see what the switch statement is achieving there. All you need is to apply range checks to the time value to decide which display format to use, followed by a call to the corresponding output function. You already have the range checks in the code there, and if you throw away the switch and simply run through the sequence of if / else if statements it should do what you want.

I only provide help via the forum - please do not contact me for private consultancy.

What it was acheiving for me was making the structure simpler for me to understand. Yet it lacks a time function which might be the complicated part. As some one new to all this I'm still trying to figure out how to meld all these functions to produce a coherent system.

All you need is to apply range checks to the time value to decide which display format to use, followed by a call to the corresponding output function. You already have the range checks in the code there, and if you throw away the switch and simply run through the sequence of if / else if statements it should do what you want.

OK. I'll work on my if/else functions some more to figure this out. Last night I tried different approaches using my limited skills and I think I bruised my brain.

That approach is a lot easier to code and provides better brightness - as the display is essentially is static.

The sketch I referred to only confused me (more so than the cluster I'm dealing with now). Since I don't have a CD4021 this is a last resort. Plus my display is plenty bright. In fact I had to set the brightness at the lowest level to prevent burning my retinas.

if (100mS elapsed){// do the digit changing & display updating stuff via MAX7219 SPI.transfer commands// }// rest of the time, read buttons, do other stuff - there is a lot to processing time left to do that stuff.

Lots of things will happen when time is not running - incrementing the score, the period counter, buzzing the score indicator, etc.

So did use use all the millis() if statements to do your timeline or some other timing method?

// ***********************************************************************************************// Loop here endlessly, checking if time or score needs updating, if wireless message came in, // if touch lights are on// ***********************************************************************************************void loop(){ // check if time needs updating if ((time_running == 1) || (time_running == 2)) // fencing time is counting down or delay time is counting down { unsigned long currentMillis = millis(); // see how long its been

if ((time_running == 1) && (period>0) && (period<9)) { // update period counter if was fencing time, not 1:00 or 10:00 break period = period +1; update_period=1; // enable period display to be updated } } // end of if final second