the big thing i guess is i am going to use the chip as a standalone and completely remove the uno board
Well, that part is easy. Just need the '328P, 16 MHz crystal, two 22pf caps, 10K reset pullup resistor, 4 100nF/0.1uF caps, and 6 header pins to connect an external FTDI Basic or similar. Schematic has been posted many times. 3AA battery pack for power.
Here's some code I have that counts down from 10:00, 3:00, or 1:00.
You'll have to define all the variables & stuff in setup, but this shows how to use blink-without-delay type coding to watch for a time to pass and then do something.
The rest of the time, you can read the state of your buttons, set the time variables as needed per your button presses, and incorporate your LED muxing code - every 5 mS, update the digit selected and the cathode/segments being displayed.
I used a MAX7219 to control 8 digits, 4 of which were time; but since MAX7219 did the multiplexing, I only set a flag to let MAX7219 section of code know something needed to be done, and it cleared the flag when it did it. I suppose that could also be written as a function.
My code flow looked like this:
void loop(){
Time passed to update the time digits?
Yes, update and set time update flag
Rx command received?
Yes, execute switch:case command to :
start/stop time running flag
update time variables
update score variables
etc
Left or Right score made?
Yes, update score variable, clear time running flag, set score update flag
Time updated or score updated flag set?
Yes, update time or score register(s) in MAX7219, clear appropriate flag
}
No functuions at all just setting/clearing flags and acting on set flags.
Each major chunk was its own tab in the IDE.
This was the tab that started void loop and did the time countdown
// ***********************************************************************************************
// 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) // fencing time is counting down or delay time is counting down
{
unsigned long currentMillis = millis(); // see how long its been
if (currentMillis - previousMillis >= interval) // more than our quarter second interval?
{
// save the last time we okayed time updates
previousMillis = previousMillis + interval;
update_time = 1; // enable time display to be updated
// update the time digits
// cases:
// 0:01, final second - stop time, disable touch lights, sound buzzer
// Tens of seconds rollover: time = x:50, x:40, x:30, x:20, x:10: decrement tens of seconds, rollover seconds to 9
// Minutes rollover: time = 9:00, 8:00, etc. 2:00, 1:00: decrement ones of minutes, rollover tens of
// seconds to 5, ones of seconds to 9
// 10:00: Roll all the digits over
// otherwise: just roll over the seconds
// Case: Final Second
if ((minutes_ones == 0) && (seconds_tens == 0) && (seconds_ones == 1)) // don't need minutes_tens, can't have 10:01
{
time_running = 0; // stop time running
seconds_ones = 0; // clear the last second
updated = 1; // fake a Case complete flag
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
// Case: x:50, x:40, x:30, x:20, x:10
if ((seconds_tens >0) && (seconds_ones == 0)) // case for the last tens of seconds
{
seconds_tens = seconds_tens - 1; // decrement the tens
seconds_ones = 9; // rollover the ones
updated = 1;
} // end of if 10 of seconds rollover
// Case: 9:00, 8:00, etc 2:00, 1:00
if ((minutes_ones > 0) && (seconds_tens == 0) && (seconds_ones == 0)) // case for the last ones of minutes
{
minutes_tens = 0x00; //
minutes_ones = minutes_ones - 1; // decrement the minutes
seconds_tens = 5; // rollover the tens of seconds;
seconds_ones = 9; // rollover the ones of seconds;
updated = 1;
} // end of if minutes rollover
// Case: starting from 10:00
if (minutes_tens == 0x01) // roll over all digits
{
minutes_tens = 0x00; // rollover the tens of minutes
minutes_ones = 9; // rollover the ones of mints;
seconds_tens = 5; // rollover the tens of seconds;
seconds_ones = 9; // rollover the ones of seconds;
updated = 1;
} // end of if 10:00 rollover
// General Case: just decrement the seconds
if (updated == 0) // nothing else updated - but don't decrement if = 0.
{
seconds_ones = seconds_ones - 1;
}
updated = 0; // reset for next pass thru
} // end of reaching our interval
} // end of if time_running
else
{
update_time = 0; // no time update this time around - probably don't need this
}