Hi Robert.. I tried that but no change??
I have highlighted where I made the change in the code below.
I presume I am correct by grounding pin 6 on the Arduino?
byte pause_button_state = 0;
byte pause_button = 6;
byte paused = 0;
unsigned long start_pausetime = 0;
unsigned long end_pausetime = 0;
unsigned long elapsed_pausetime = 0;
unsigned long pause_interval= 0;
unsigned long currentmillis = 0;
unsigned long previousmillis = 0;
unsigned long interval = 10000;
unsigned long elapsedmillis = 0;
byte latchpin = 8; // connect to pin 12 on the 74HC595
byte clockpin = 12; // connect to pin 11 on the 74HC595
byte datapin = 11; // connect to pin 14 on the 74HC595
byte ones_seconds = 0;
byte tens_seconds = 0;
byte ones_minutes = 0;
byte tens_minutes = 0;
byte tenths = 0;
byte hundredths = 0;
byte ones_hours = 0;
byte tens_hours = 0;
int segdisp[10] = {
63,6,91,79,102,109,125,7,127,111 }; //segment references using 74HC595 Shift Registers
//The above numbers light up different segments of a digit
int time_update = 0;// added new flag
void setup()
{
pinMode(latchpin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(datapin, OUTPUT);
pinMode(pause_button, INPUT);
digitalWrite (pause_button, HIGH);
}
void loop()
{
currentmillis = micros(); // read the time.
elapsedmillis = currentmillis - previousmillis;
if (elapsedmillis >= interval) // 10 milliseconds have gone by
{
previousmillis = previousmillis + elapsedmillis; // save the time for the next comparison
time_update = 1;
}
if (time_update == 1){ // no updating if not at 10ms interval, skip this whole section
// increment the counters, roll as needed, shift the digits out
time_update = 0; // reset for next pass thru
hundredths = hundredths +1;
if (hundredths == 10){
hundredths = 0;
tenths = tenths +1;
}
if (tenths == 10){
tenths = 0;
ones_seconds = ones_seconds +1;
}
if (ones_seconds == 10){
ones_seconds = 0;
hundredths = hundredths +3; // Speed up the clock!
tens_seconds = tens_seconds +1;
}
if (tens_seconds == 6){
tens_seconds = 0;
hundredths = hundredths +6;
ones_minutes = ones_minutes +1;
}
if (ones_minutes == 10){
ones_minutes = 0;
tens_minutes = tens_minutes +1;
}
if (tens_minutes == 6){
tens_minutes = 0;
ones_hours = ones_hours +1;
}
if (ones_hours == 13){ // I added hours; this is the last digit you check before shiftout
ones_hours = 0;
tens_hours = tens_hours +1;
}
if (paused == 0){
// your shiftout code is in here
// counters are all updated now, just do the shiftout one time here:
digitalWrite(latchpin, LOW); // send the digits down to the shift registers!
shiftOut(datapin, clockpin, MSBFIRST, segdisp[hundredths]); // print the % first "hundredths" digit
shiftOut(datapin, clockpin, MSBFIRST, segdisp[tenths]); // print the tens of hundredths digit
shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_seconds]); // print the % first "seconds" digit
shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_seconds]); // print the tens of seconds digit
shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_minutes]); // print the % first "minute" digit
shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_minutes]); // print the tens of minutes digit
digitalWrite(latchpin, HIGH);
// after the shifouts, read the pause button, set a flag if pressed, capture the time it was pressed
pause_button_state = digitalRead(pause_button);
if ([glow]pause_button_state[/glow] == 0){
paused = 1;
start_pausetime = millis();
}
}
// if paused, see for how long, if long enough clear the flag
else {
end_pausetime = millis();
elapsed_pausetime = end_pausetime - start_pausetime; //
if (elapsed_pausetime >= pause_interval){
paused = 0;
}
}
} // end if time to be updated
} // end void loop