2 button Stopwatch with hours, minutes & seconds

Hi,
This is my first post to the forum so please go easy with me. I’m also a new by with Arduino so please go even easier

What is your problem please explain and give us all the details of your project

My main problem is finding a way to use the same button to carry out the start, stop and carry on from where the time was stopped at.

Are you using the realtime module for the time ?

No, I am just using a Nano or Uno. I don't need the actual time. I just need the time since the start button pressed that is why I was just going to use Mullis. But If there is now way to do it I do have a rtc that I could connect up

Assuming you mean "millis" that should be fine. So post the program that you have so far and explain what it currently does.

Or if you haven't yet made a start Google "Arduino stopwatch" and that should give you plenty of useful starting points.

Steve

This is the code that I am using but I can't seem to get the stopwatch to carry on from where it was paused. When I push the button connected to pin 2 the timer starts counting again from zero instead of where it was paused.
Is it possible to create a variable which would hold the time from when button two was pressed and then when the button is pressed again add the time from the variable to the zero count and carry on running from where it left off?

// include the library code:
#include <LiquidCrystal.h>
#include <Bounce2.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 6, rw = 5, en = 4, d4 = 8, d5 = 9, d6 = 10, d7 = 11;

//LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)
LiquidCrystal lcd(rs, rw, en, d4, d5, d6, d7);

const byte ledPin = 13;
//int ledPin = 13;
const byte startButton = 2;
// Instantiate a Bounce object
Bounce startDebouncer1 = Bounce();

const byte resetButton = 3;
// Instantiate another Bounce object
Bounce resetDebouncer2 = Bounce();

void setup() {
// pinMode(LED_BUILTIN, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(startButton, INPUT_PULLUP);
// After setting up the button, setup the Bounce instance :
startDebouncer1.attach(startButton);
startDebouncer1.interval(5); // interval in ms

pinMode(resetButton, INPUT_PULLUP);
// After setting up the button, setup the Bounce instance :
resetDebouncer2.attach(resetButton);
resetDebouncer2.interval(5); // interval in ms

// clear screen for the next loop:
lcd.clear();

lcd.setCursor(0, 0);
lcd.print("Press Red button");
}

bool startState = LOW;
bool resetState = LOW;

unsigned long startMillis;
unsigned long currentMillis;
unsigned long elapsedMillis;

void loop() {
// Update the Bounce instances :
startDebouncer1.update();

if ( startDebouncer1.fell() ) { // Call code if button transitions from HIGH to LOW
startState = !startState; // Toggle start button state
startMillis = millis();
}

if (startState)
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
currentMillis = millis();
elapsedMillis = (currentMillis - startMillis);

lcd.setCursor(0, 0);
lcd.print("SW (hh:mm:ss:ms)");
lcd.setCursor(0, 1);
lcd.print(" ");

unsigned long durMS = (elapsedMillis%1000); //Milliseconds
unsigned long durSS = (elapsedMillis/1000)%60; //Seconds
unsigned long durMM = (elapsedMillis/(60000))%60; //Minutes
unsigned long durHH = (elapsedMillis/(3600000)); //Hours
durHH = durHH % 24;

String durMilliSec = timeMillis(durHH, durMM, durSS,durMS);
lcd.setCursor(0, 1);
lcd.print(durMilliSec);
delay(150);
}

resetDebouncer2.update();

if (resetDebouncer2.fell())
{
resetState = HIGH;
}

if (resetState)
{
digitalWrite(LED_BUILTIN, LOW); // turn the LED off (LOW is the voltage level)
// clear screen for the next loop:
lcd.clear();

lcd.setCursor(0, 0);
lcd.print("Press Red Start");

// lcd.setCursor(0, 1);
// lcd.print("Press R-Reset");

delay(100);

resetState = LOW;
}

}

String timeMillis(unsigned long Hourtime,unsigned long Mintime,unsigned long Sectime,unsigned long MStime)
{
String dataTemp = "";

if (Hourtime < 10)
{
dataTemp = dataTemp + "0" + String(Hourtime)+ "h:";
}
else{
dataTemp = dataTemp + String(Hourtime)+ "h:";
}

if (Mintime < 10)
{
dataTemp = dataTemp + "0" + String(Mintime)+ "m:";
}
else{
dataTemp = dataTemp + String(Mintime)+ "m:";
}

if (Sectime < 10)
{
dataTemp = dataTemp + "0" + String(Sectime)+ "s:";
}
else{
dataTemp = dataTemp + String(Sectime)+ "s:";
}

dataTemp = dataTemp + String(MStime);

return dataTemp;
}