Stopwatch with Pause/Lap  6 digit 7 seg LED. HELP!

Hi Warren, at this time should be run, but I do not know how to buttons should be run, please test it. And write diferencies between both versions. Should be the same.... And there is again two parts of code... :slight_smile:

#include <EEPROM.h>

// Variables
unsigned long currentmicros = 0;
unsigned long previousmicros = 0;
unsigned long interval = 10000;
unsigned long elapsedmicros = 0;

volatile byte hundredths= 0;
volatile byte tenths = 0;
volatile byte ones_seconds = 0;
volatile byte tens_seconds = 0;
volatile byte ones_minutes = 0;
volatile byte tens_minutes = 0;
volatile byte ones_hours = 0;
volatile byte tens_hours = 0; 

byte copy_hundredths= 0;
byte copy_tenths = 0;
byte copy_ones_seconds = 0;
byte copy_tens_seconds = 0;
byte copy_ones_minutes = 0;
byte copy_tens_minutes = 0;
byte copy_ones_hours = 0;
byte copy_tens_hours = 0;

// Variables for work with EEPROM 
int value;
int EEPROM_address = 0;
byte byte_to_read = 0;
byte byte_to_write = 0;
byte EEPROM_writing =0;
byte EEPROM_reading =0;
byte EEPROM_read =0;

// start_pausetime, end_pausetime used for button debounce
unsigned long start_pausetime = 0;   
unsigned long end_pausetime = 0;
unsigned long elapsed_pausetime = 0;

// Table for 7segments - numbers light up different segments of a digit
int segdisp[10] = {63,6,91,79,102,109,125,7,127,111 }; //segment references using 74HC595 Shift Registers

// Hardware setup:
// Displays:
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

// Buttons and states
volatile byte memory_up_button_state = 0;
byte memory_up_button = 10;

volatile byte reset_button_state = 0;
byte reset_button = 2;

volatile byte pause_button_state = 0;
byte pause_button = 6;

// Flags
volatile byte paused = 0;
volatile byte started = 0;
volatile byte time_update = 0;


void setup()
{
  // Hardware setup:
  Serial.begin (115200);

  // Outputs
  pinMode(latchpin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(datapin, OUTPUT);

  // Inputs
  pinMode(memory_up_button, INPUT);
  digitalWrite (memory_up_button, HIGH); // enable pullup

  pinMode(pause_button, INPUT);
  digitalWrite (pause_button, HIGH); // enable pullup

  pinMode(reset_button, INPUT);
  digitalWrite (reset_button, HIGH); // enable pullup

  //First test of display:
 ////  Serial.println ("Test displays routine");
  Test_Display ();
}

//---------------------------- Main loop--------------------------------------------------------------------------------------------
void loop()
{
  //Memory Up Button Here
  memory_up_button_state = digitalRead (memory_up_button);
  if (memory_up_button_state == 0 | paused == 1)
  {
   //  Serial.println ("Memory up pressed");
    /* add in paused check, lets us finish reading after button goes back high
     if the lap times seem to read out/udpate more than once on a button push, may need to add in time check delay (ex. check
     millis, make sure 1000 goes by before button is read again) so don't get false read commands from button bouncing */

    EEPROM_reading = 1;
    value = EEPROM.read(EEPROM_address);

    if (EEPROM_reading == 1)
    {
     //  Serial.println ("Should be Read_from_EEPROM here:");
      Read_from_EEPROM ();
     //  Serial.println ("Should be Display here:");
      Display();
    }//End of EEPROM reading
  } // End of checking memory button state 

  {//Reset Button Here
    reset_button_state = digitalRead (reset_button);
    if (reset_button_state == 0)
    {
     //  Serial.println ("Reset button pressed");
      paused = 1;
     //  Serial.println ("Should be Counters_to_zero here:");
      Counters_to_zero ();

      time_update = 0;
     //  Serial.println ("Should be Display here:");
      Display();
      started = 0;
      paused = 0;
    } // End of reset_button_state == 0

    {// If not started, read the pause button, set started flag once pressed
      pause_button_state = digitalRead (pause_button);
      if (pause_button_state == 0 & started == 0)
      {
        // Start - first time Pause button pressed, display running
        started = 1;
        start_pausetime = millis(); // start_pausetime, end_pausetime used for button debounce
       //  Serial.println ("Start - first time Pause button pressed, display running");
      }

      // when started flag is pressed, start counting in 10mS increments
      if (started == 1)
      {
        currentmicros = micros();  // read the time.
        elapsedmicros = currentmicros - previousmicros;

        if (elapsedmicros >= interval) // 10 milliseconds have gone by
        {
          previousmicros  = previousmicros + elapsedmicros;  // save the time for the next comparison
          time_update = 1; // set flag to shift out the new time
        }
        if (time_update == 1) // no updating if not at 10ms interval, skip this whole section
        {
          time_update = 0; // reset for next pass thru
         //  Serial.println ("Should be Count here:");
          Count();
        }
        if (paused == 0)
        {
          //not paused, update the display
         //  Serial.println ("Pause button pressed second time, display stopped");
          // counters are all updated now, just do the shiftout one time here:
         //  Serial.println ("Should be Display here:");
          Display ();
        }


        // read the pause button, set a flag if pressed, capture the time it was pressed, reset the lap time
        end_pausetime = millis();

        if (paused == 0 & (end_pausetime - start_pausetime > 500)) // not paused, debounced if had been (long time used due to crappy button)
        {
          pause_button_state = digitalRead(pause_button);
          //PAUSED HERE
          if (pause_button_state == 0)
          {
            paused = 1;
            start_pausetime =  end_pausetime;
            //MAKE COPPIES
            copy_hundredths= hundredths;
            copy_tenths = tenths;
            copy_ones_seconds = ones_seconds;
            copy_tens_seconds = tens_seconds;
            copy_ones_minutes = ones_minutes;
            copy_tens_minutes = tens_minutes;
            copy_ones_hours = ones_hours;
            copy_tens_hours = tens_hours;
            //WRITE THE COPPIES TO EEPROM
            if (EEPROM_writing == 1)
            {
             //  Serial.println ("Should be Write_to_EEPROM here:");
              Write_to_EEPROM ();
            } // End of EEPROM_writing == 1
            currentmicros = micros();  // read the time.
            previousmicros = currentmicros;
            elapsedmicros = currentmicros - previousmicros;
           //  Serial.println ("Should be Counters_to_zero here:");
            Counters_to_zero ();

          }// End of pause_button_state == 0
        } // End of not paused, debounced if had been (long time used due to crappy button)

        // read the pause button; unpause to let time display be shown
        end_pausetime = millis();
        if (paused ==1 & (end_pausetime - start_pausetime >500)) // sitting in paused state now, is debounced
        {
          pause_button_state = digitalRead (pause_button);
          if (pause_button_state == 0)
          {
            paused = 0;// back to unpaused
            start_pausetime = end_pausetime;
          } // End of pause_button_state == 0 
        }// End of sitting in paused state now, is debounced
      }// End of when started flag is pressed, start counting in 10mS increments
    }// End of If not started, read the pause button, set started flag once pressed
  }// End of Reset Button Here

} // end of main loop
//---------------------------- End of main loop-------------------------------------------------------------------------------------


//---------------------------- Display on displays----------------------------------------------------------------------------------
void Display ()
{
 //  Serial.println ("Display");
  digitalWrite(latchpin, LOW); // send the digits down to the shift registers!
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[hundredths]); // print the hundredths digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[tenths]);     // print the tenths digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_seconds]); // print the lower seconds digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_seconds]); // print the upper seconds digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_minutes]); // print the lower sinutes digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_minutes]); // print the upper minutes digit
  digitalWrite(latchpin, HIGH);
  if (tenths == 0 && hundredths == 0) // update on screen once a second
  {
    Serial.print (tens_hours, DEC);
    Serial.print (ones_hours, DEC);
    Serial.print (":");
    Serial.print ( tens_minutes, DEC);
    Serial.print (ones_minutes, DEC);
    Serial.print (":");
    Serial.print (tens_seconds, DEC);
    Serial.print(ones_seconds, DEC);
    Serial.print (".");
    Serial.println (tenths, DEC);
   //  Serial.println (hundredths, DEC);
  }// End of serial send
}

//---------------------------- End of Display on displays---------------------------------------------------------------------------