"I have not been able to find what I want on the web "
All of those have been discussed numerous times here in the forum, more info is found in the Learning section, and in the Playground.
For example, look at this code to keep track of 4 digits of data in a count down timer.
void loop()
{
// check if time needs updating
if ((time_running == 1)) // time is counting down
{
unsigned long currentMillis = millis(); // see how long its been
if (currentMillis - previousMillis >= interval) // more than our [s]quarter[/s] tenth second interval?
{
// save the last time we okayed time updates
previousMillis = currentMillis;
tenths = tenths+1;
if (tenth_interval == 10) // we hit the one second update time
{
update_time = 1; // enable time display to be updated
tenth_interval = 0;
// update the time digits
// cases:
// 0:01, final second - stop time
// 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
buzzer = 1; // add a buzzer for this: end of time buzzer sounds
} // 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 if [s]quarter[/s]tenth_interval
} // end of reaching our interval
} // end of if time_running
Flesh out the variables, add some code to read start/stop button and set time_running to 0 or 1, reset button to set the starting time you want (10:00, 3:0 etc), create an 10 element array to hold your digit definitions,
displayArray[] = {B101111111, etc. for 1,2,3,4,5,6,7,8,9};
where each byte represents decimal point, g,f,d,e,c,b,a, in this case 1 = on, could also use 0 = on depending on your hardware setup
and segments are set up thus:
a
f b
g
e c
d
and shift out the data to 4 shift registers to drive the 7 segment display when you set the flag saying display_update is needed.
if (updated == 1){
updated = 0; // clear flag
digitalWrite (SlaveSelect, LOW);
SPI.transfer (digit0);
SPI.transfer (digit1);
SPI.transfer (digit2);
SPI.transfer (digit3);
digitalWrite (SlaveSelect, HIGH);
}