Adding stop/start button and reset button to stopwatch

Hi Champs

i was working on a project for a stopwatch that shows millis and have successfully adjusted it with the help of the awesome guys here

currently i am trying to add two press buttons for it one for start to be pressed once to enable counting ,then to be ressed once to stop counting ,also a reset button to reset the count back to zeros once it is pressed

here is the code that i have made so far

#include "RTClib.h"

//Setup the Real Time Clock, DS3231
RTC_DS3231 rtc;

// Arduino pin used to monitor the SQW 1Hz output from the DS3231.
// Pin 2 is an "interrupt-capable" pin on the Arduino Uno.  Note
// that different Arduino boards have specific pins which are
// inerrupt capable. Refer to:
// www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
// for a complete list.
const byte SQWinput = 2;  // Must be External Interrupt

volatile uint32_t  MillisecondsAtStartOfSecond = 0;
 
 unsigned long secondss=0 ;
 unsigned long minutess=0 ;
 
 unsigned long  hourss =0;


boolean passed_second=true;
boolean start=true;


const char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

// The SQW pin, when set to 1 Hz mode, has a falling edge at the beginning of every second.
void SQWFallingISR()
{
  MillisecondsAtStartOfSecond = millis();
}

void setup ()
{
  Serial.begin(115200); // Set Serial Monitor to 115200
  delay(200);

  pinMode(SQWinput, INPUT_PULLUP);

  if (! rtc.begin())
  {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  if (rtc.lostPower())
  {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2022, 4, 03, 21, 14, 0));
  }

  // Configure SQW pin on the DS3231 to output a 1Hz squarewave 
  rtc.writeSqwPinMode(DS3231_SquareWave1Hz);

  // Get MillisecondsAtStartOfSecond on the falling edge of SQW.
  attachInterrupt(digitalPinToInterrupt(SQWinput), SQWFallingISR, FALLING);
}

void loop ()
{
  DateTime now = rtc.now();
  unsigned long ms = millis();
  
  noInterrupts();
  // How long since the second started?
  ms -= MillisecondsAtStartOfSecond;
  interrupts();

  
  displayTime (now, ms);
  Serial.println("stopwatch  ");
  Serial.print(ms);
  Serial.print(':');
  Serial.print(secondss);
  Serial.print(':');
  Serial.print(minutess);
  Serial.print(':');
  Serial.println(hourss);
   Serial.println("Clock  ");
               
}

void displayTime(DateTime &now, unsigned long ms)
{
  ms = ms % 1000;  // Ignore full seconds
  
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(" (");
  Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
  Serial.print(") ");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  if (now.minute() < 10)
    Serial.print('0');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  if (now.second() < 10)
    Serial.print('0');
  Serial.print(now.second(), DEC);
 // Serial.println();
  Serial.print(':');
  if (ms < 100)
    Serial.print('0');
  if (ms < 10)
    Serial.print('0');
  Serial.print(ms, DEC);
  Serial.println();

  if(ms>998) {
      secondss++;
     
  }
    if(secondss>59) {
     secondss=0;
      minutess++;
 
    }
    if(minutess>59) {
     minutess=0;
      hourss++;}

    }
  

1. Connect the RST, START, and STOP switches (push type) with UNO as per Fig-1.
rtc3231-2sw3

Figure-1:

2. Add the following lines at the appropriate places of your sketch of post #1.

Set directions of the IO lines of the switches:

pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);

Polling the START switch:

while(digitalRead(5) != LOW)
{
     ;  //wait
}

Polling the STOP switch:

if(digitalRead(6) != LOW)
{
     ;     //keep running the Stop Watch
}
else
{
     //code to STOP the watch
}

Polling the RST switch

if(digitalRead(4) != LOW)
{
     ;     //keep running the Stop Watch
}
else
{
     //reset the Stop Watch to 0
}

Here is a stopwatch sketch I wrote. Maybe you can find something here that can help you with your design.

/////////////////////////////////////
//  Seven-Segment Stopwatch Example
//
//  Written by: John Wasser
/////////////////////////////////////

// Bit maps for the seven segment display
// Segment Cathodes (0/LOW for on, 1/HIGH for off)
const byte Segments[] =
{
  0b11000000, // 0
  0b11001111, // 1
  0b10100100, // 2
  0b10000110, // 3
  0b10001011, // 4
  0b10010010, // 5
  0b10010000, // 6
  0b11000111, // 7
  0b10000000, // 8
  0b10000011, // 9
};

const byte ColonLowerDot = 12;
const byte ColonUpperDot = 13;

// List of digit select lines, least significant digit first
// Digit Common Anodes (HIGH for on, LOW for off)
const byte DigitCount = 4;
const byte DigitPins[DigitCount] = {A0, 2, 3, 4};

// Segment Cathodes (LOW for on, HIGH for off)
const byte SegmentCount = 7;
const byte SegmentPins[SegmentCount] = {5, 6, 7, 8, 9, 10, 11};

const byte StartButtonPin = A1;  // Button wired from pin to GND
const byte StopResetButtonPin = A2; // Button wired from pin to GND
bool StartButtonWasPressed = false;
bool StopResetButtonWasPressed = false;

unsigned long DebounceTimer = 0;
const unsigned DebounceTime = 10;

bool IsRunning = false;
unsigned long ElapsedTime = 0;
unsigned long LastStartTime = 0;


void setup()
{
  pinMode(StartButtonPin, INPUT_PULLUP);
  pinMode(StopResetButtonPin, INPUT_PULLUP);

  for (int i = 0; i < DigitCount; i++)
  {
    pinMode(DigitPins[i], OUTPUT);
    digitalWrite(DigitPins[i], LOW);
  }

  for (int i = 0; i < SegmentCount; i++)
  {
    pinMode(SegmentPins[i], OUTPUT);
    digitalWrite(SegmentPins[i], HIGH);
  }

  digitalWrite(ColonLowerDot, HIGH);
  digitalWrite(ColonUpperDot, HIGH);

  pinMode(ColonLowerDot, OUTPUT);
  pinMode(ColonUpperDot, OUTPUT);
}



void loop()
{
  unsigned long currentTime = millis();

  bool startButtonIsPressed = digitalRead(StartButtonPin) == LOW;
  bool stopResetButtonIsPressed = digitalRead(StopResetButtonPin) == LOW;

  // State Change Detection and debounce
  if (startButtonIsPressed != StartButtonWasPressed &&
      currentTime - DebounceTimer > DebounceTime)
  {
    // Button has changed state
    StartButtonWasPressed = startButtonIsPressed;
    DebounceTimer = currentTime;

    if (startButtonIsPressed)
    {
      // Just Pressed START
      if (!IsRunning)
      {
        // Starting/Restarting the timer
        LastStartTime = currentTime;
        IsRunning = true;
      }
      else
      {
        // Pausing the timer
        IsRunning = false; // Paused
        ElapsedTime += currentTime - LastStartTime;
      }
    }
  }

  // State Change Detection and debounce
  if (stopResetButtonIsPressed != StopResetButtonWasPressed &&
      currentTime - DebounceTimer > DebounceTime)
  {
    // Button has changed state
    StopResetButtonWasPressed = stopResetButtonIsPressed;
    DebounceTimer = currentTime;

    if (stopResetButtonIsPressed)
    {
      // Just Pressed STOP/RESET
      if (IsRunning)
      {
        // Pausing the timer
        IsRunning = false; // Paused
        ElapsedTime += currentTime - LastStartTime;
      }
      else
      {
        // Was not running so reset everything
        ElapsedTime = 0;
        IsRunning = false;
      }
    }
  }

  // Get time since last reset
  unsigned long DisplayTime;
  if (IsRunning)
    DisplayTime = ElapsedTime + (currentTime - LastStartTime);
  else
    DisplayTime = ElapsedTime;

  unsigned long hundredths = DisplayTime / 10;
  unsigned long seconds = hundredths / 100;
  unsigned long minutes = seconds / 60;
  int hours = minutes / 60;
  int clock;

  if (seconds < 100)
    // Display seconds.hundredths up to 100 seconds, then minutes:seconds
    clock = (seconds % 100) * 100 + (hundredths % 100);
  else if (minutes < 100)
    // Display minutes:seconds up to 100 minutes, then hours/minutes
    clock = (minutes % 100) * 100 + (seconds % 60);
  else
    clock = (hours % 100) * 100 + (minutes % 60);

  // Clear all segments before enabling a digit
  for (int s = 0; s < SegmentCount; s++)
  {
    digitalWrite(SegmentPins[s], HIGH);
  }

  // Display each digit, right to left
  for (int i = 0; i < DigitCount; i++)
  {
    // Peel a digit off the low end of the number
    int digit = clock % 10;
    clock /= 10;

    // Blank the MSD if it is zero
    if (i == 3 && digit == 0)
    {
      for (int s = 0; s < SegmentCount; s++)
        digitalWrite(SegmentPins[s], HIGH);
    }
    else
    {
      // Display the digit on the seven segments
      unsigned char segments = Segments[digit];
      for (int s = 0; s < SegmentCount; s++)
      {
        digitalWrite(SegmentPins[s], segments & 1);
        segments >>= 1;
      }
    }

    if (seconds < 100)
    {
      // Steady decimal point when showing seconds and hundredths
      digitalWrite(ColonLowerDot, HIGH);
      digitalWrite(ColonUpperDot, LOW);
    }
    else if (minutes < 100)
    {
      // Steady colon when showing minutes and seconds
      digitalWrite(ColonLowerDot, LOW);
      digitalWrite(ColonUpperDot, LOW);
    }
    else
    {
      // Make the colon blink each second
      digitalWrite(ColonLowerDot, seconds & 1);
      digitalWrite(ColonUpperDot, seconds & 1);
    }

    // Turn on the digit briefly
    digitalWrite(DigitPins[i], HIGH);  // Select one digit
    delayMicroseconds(3000UL);  // Higher numbers give higher brightness but more flicker
    digitalWrite(DigitPins[i], LOW);
  }
}
1 Like

Hello My Friend

welcome back

it is impressive code but totally built in another way than what i am struggling off now

is there any clue so that i can add start/stop button to my code ,i think reset button is achievable

Have you seen post #2 connecting RST, START, and STOP swicthes?

Hello Golam

thank u very much for your reply

what i am trying to build is a code using sq output of the chinp which is totally different than what u have included in your code as well as your diagram

You are building a Stop Watch that is supposed to show Milliseconds on the Serial Monitor. You are using DS3231 from which you can get 1-sec time quanta and not less than that. Under this condition, you can show 1000 ms, 2000 ms, and so on. If you are using millis() function for your project, then what is the purpose of using RTC?

A Stop Watch counts time in the following format:
MIN : SEC : 1/1000 sec
===> 1 : 15 : 354 //1-minute 15 seconds 354 milliseconds

@GolamMostafa i am using sq wave output of the chip not its RTC

@johnwasser

i have tried this code and it is working fine but it is totally different from the targeted approach as it is not related to millis approach that u have helped me to do before

any suggestion for that?

i have made this attempt

it is working but the the seconds ,minutes,and hours are not incrementing

#include "RTClib.h"
//Setup the Real Time Clock, DS3231
RTC_DS3231 rtc;

const byte SQWinput = 2;  // Must be External Interrupt

volatile uint32_t  MillisecondsAtStartOfSecond = 0;
 
 unsigned long secondss=0 ;
 unsigned long minutess=0 ;
 
 unsigned long  hourss =0;
 unsigned long ms;

boolean passed_second=true;
boolean start=true;


const byte ledPin = 13;

const byte startButton = 7;


const byte resetButton = 3;
// Instantiate another Bounce object


const char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

// The SQW pin, when set to 1 Hz mode, has a falling edge at the beginning of every second.
void SQWFallingISR()
{
  MillisecondsAtStartOfSecond = millis();
}

void setup ()
{
  Serial.begin(9600); // Set Serial Monitor to 115200
  delay(200);

  pinMode(7, INPUT);
  digitalWrite(7, HIGH);
  pinMode(3, INPUT);
  digitalWrite(3, HIGH);
 


  
  if (! rtc.begin())
  {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  if (rtc.lostPower())
  {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2022, 4, 03, 21, 14, 0));
  }

  // Configure SQW pin on the DS3231 to output a 1Hz squarewave 
  rtc.writeSqwPinMode(DS3231_SquareWave1Hz);

  // Get MillisecondsAtStartOfSecond on the falling edge of SQW.
  attachInterrupt(digitalPinToInterrupt(SQWinput), SQWFallingISR, FALLING);
}



void loop ()
{
  DateTime now = rtc.now();


    ms = millis();
 
  noInterrupts();
  // How long since the second started?
  
 
  ms -= MillisecondsAtStartOfSecond;
  interrupts();

  if(digitalRead(7) != HIGH)   //START BUTTON
{    displayTime (now, ms);
     Serial.println("stopwatch  ");
  
  Serial.print(hourss);
  Serial.print(':');
  Serial.print(minutess);
  Serial.print(':');
  Serial.print(secondss);
  Serial.print(':');
  Serial.println(ms);
}

 if(digitalRead(3) != HIGH)   //RESET BUTTON
{
     Serial.println("stopwatch  ");
  
  Serial.print(0);
  Serial.print(':');
  Serial.print(0);
  Serial.print(':');
  Serial.print(0);
  Serial.print(':');
  Serial.println(0);
  ms=0;
}
 // displayTime (now, ms);
  /*Serial.println("stopwatch  ");
  
  Serial.print(hourss);
  Serial.print(':');
  Serial.print(minutess);
  Serial.print(':');
  Serial.print(secondss);
  Serial.print(':');
  Serial.println(ms);
  Serial.println("*********************************");
  Serial.println("Clock & Date  ");*/
   

  }

void displayTime(DateTime &now, unsigned long ms)
{
  ms = ms % 1000;  // Ignore full seconds
  
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(" (");
  Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
  Serial.print(") ");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  if (now.minute() < 10)
    Serial.print('0');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  if (now.second() < 10)
    Serial.print('0');
  Serial.print(now.second(), DEC);
 // Serial.println();
  Serial.print(':');
  if (ms < 100)
    Serial.print('0');
  if (ms < 10)
    Serial.print('0');
  Serial.print(ms, DEC);
  Serial.println();
  Serial.println("*********************************");

  if(ms>998) {
      secondss++;
     
  }
    if(secondss>59) {
     secondss=0;
      minutess++;
 
    }
    if(minutess>59) {
     minutess=0;
      hourss++;}

    }
  

Any help how to fix that?

It looks like you only increment 'secondss' in 'displayTime()' and you only call 'displayTime()' in:

  if(digitalRead(7) != HIGH)   //START BUTTON
{    displayTime (now, ms);

I think that means the time is not going to count if you are not holding down the START button. If you look at the example I wrote, there is a 'Running' flag to keep track of when the stopwatch is running and when it is not. Time should accumulate whenever the stopwatch is running.

There is a problem in 'displayTime()' where you display the time before you calculate the current time. You also throw away whole seconds from 'ms' before you move those full seconds into 'secondss'.

1 Like

so shall i put displaytime inside that if stateent?

I don't know what you mean by "that if statement". If you mean the one it is already in, I'd say no.

1 Like
if(digitalRead(7) != HIGH)   //START BUTTON
{    displayTime (now, ms);

i mean this one

if not what am i missing ?

See reply 11 where I tell you that "the time is not going to count if you are not holding down the START button." Do you WANT the time to count only when you are holding down the 'start' button?!?

1 Like

Hi @johnwasser

i want the button to be pressed once as start and when pressed again to stop ,and if reset button is pressed the count go to zero

sorry but i am still beginner and learning from experts like u

So something like this?

void loop()
{
  unsigned long currentTime = millis();

  bool startButtonIsPressed = digitalRead(StartButtonPin) == LOW;
  bool stopResetButtonIsPressed = digitalRead(StopResetButtonPin) == LOW;

  // State Change Detection and debounce
  if (startButtonIsPressed != StartButtonWasPressed &&
      currentTime - DebounceTimer > DebounceTime)
  {
    // Button has changed state
    StartButtonWasPressed = startButtonIsPressed;
    DebounceTimer = currentTime;

    if (startButtonIsPressed)
    {
      // Just Pressed START
      if (!IsRunning)
      {
        // Starting/Restarting the timer
        LastStartTime = currentTime;
        IsRunning = true;
      }
      else
      {
        // Pausing the timer
        IsRunning = false; // Paused
        ElapsedTime += currentTime - LastStartTime;
      }
    }
  }

  // State Change Detection and debounce
  if (stopResetButtonIsPressed != StopResetButtonWasPressed &&
      currentTime - DebounceTimer > DebounceTime)
  {
    // Button has changed state
    StopResetButtonWasPressed = stopResetButtonIsPressed;
    DebounceTimer = currentTime;

    if (stopResetButtonIsPressed)
    {
      // Just Pressed STOP/RESET
      if (IsRunning)
      {
        // Pausing the timer
        IsRunning = false; // Paused
        ElapsedTime += currentTime - LastStartTime;
      }
      else
      {
        // Was not running so reset everything
        ElapsedTime = 0;
        IsRunning = false;
      }
    }
  }

I provided that in Reply 3.

1 Like

i have tried it but did not work for me when u post it in your previous reply

let me give it another try and send to u the updates

Thanks a MILLION my friend

@johnwasser

i have tried this time ,but with no luck too :pensive:

#include "RTClib.h"
//Setup the Real Time Clock, DS3231
RTC_DS3231 rtc;

const byte SQWinput = 2;  // Must be External Interrupt

volatile uint32_t  MillisecondsAtStartOfSecond = 0;
 
 unsigned long secondss=0 ;
 unsigned long minutess=0 ;

const byte StartButtonPin = 7;  // Button wired from pin to GND
const byte StopResetButtonPin = 3; // Button wired from pin to GND
bool StartButtonWasPressed = false;
bool StopResetButtonWasPressed = false;

unsigned long DebounceTimer = 0;
const unsigned DebounceTime = 10;

bool IssRunning = false;
unsigned long ElapsedTime = 0;
unsigned long LastStartTime = 0;


 
 unsigned long  hourss =0;
 unsigned long ms;

boolean passed_second=true;
boolean startt=true;





const byte resetButton = 3;
// Instantiate another Bounce object


const char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

// The SQW pin, when set to 1 Hz mode, has a falling edge at the beginning of every second.
void SQWFallingISR()
{
  MillisecondsAtStartOfSecond = millis();
}

void setup ()
{
  Serial.begin(9600); // Set Serial Monitor to 115200
  delay(200);

  pinMode(7, INPUT);
  digitalWrite(7, HIGH);
  pinMode(3, INPUT);
  digitalWrite(3, HIGH);
 


  
  if (! rtc.begin())
  {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  if (rtc.lostPower())
  {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2022, 4, 03, 21, 14, 0));
  }

  // Configure SQW pin on the DS3231 to output a 1Hz squarewave 
  rtc.writeSqwPinMode(DS3231_SquareWave1Hz);

  // Get MillisecondsAtStartOfSecond on the falling edge of SQW.
  attachInterrupt(digitalPinToInterrupt(SQWinput), SQWFallingISR, FALLING);
}



void loop ()
{
  DateTime now = rtc.now();


   unsigned long currentTime = millis();

  bool startButtonIsPressed = digitalRead(StartButtonPin) == LOW;
  bool stopResetButtonIsPressed = digitalRead(StopResetButtonPin) == LOW;

  // State Change Detection and debounce
  if (startButtonIsPressed != StartButtonWasPressed &&
      currentTime - DebounceTimer > DebounceTime)
  {
    // Button has changed state
    StartButtonWasPressed = startButtonIsPressed;
    DebounceTimer = currentTime;

    if (startButtonIsPressed)
    {
      // Just Pressed START
      if (!IssRunning)
      {
        // Starting/Restarting the timer
        LastStartTime = currentTime;
        IssRunning = true;
      }
      else
      {
        // Pausing the timer
        IssRunning = false; // Paused
        ElapsedTime += currentTime - LastStartTime;
      }
    }
  }

  // State Change Detection and debounce
  if (stopResetButtonIsPressed != StopResetButtonWasPressed &&
      currentTime - DebounceTimer > DebounceTime)
  {
    // Button has changed state
    StopResetButtonWasPressed = stopResetButtonIsPressed;
    DebounceTimer = currentTime;

    if (stopResetButtonIsPressed)
    {
      // Just Pressed STOP/RESET
      if (IssRunning)
      {
        // Pausing the timer
        IssRunning = false; // Paused
        ElapsedTime += currentTime - LastStartTime;
      }
      else
      {
        // Was not running so reset everything
        ElapsedTime = 0;
        IssRunning = false;
      }
    }
  }

  // Get time since last reset
 
  noInterrupts();
  // How long since the second started?
  
 
  // State Change Detection and debounce
  if (startButtonIsPressed != StartButtonWasPressed &&
      currentTime - DebounceTimer > DebounceTime)
  {
    // Button has changed state
    StartButtonWasPressed = startButtonIsPressed;
    DebounceTimer = currentTime;

    if (startButtonIsPressed)
    {
      // Just Pressed START
      if (!IssRunning)
      {  
         interrupts();

        // Starting/Restarting the timer
        LastStartTime = currentTime;
        IssRunning = true;
      }
      else
      {
        // Pausing the timer
        IssRunning = false; // Paused
        ElapsedTime += currentTime - LastStartTime;
      }
    }
  }

  // State Change Detection and debounce
  if (stopResetButtonIsPressed != StopResetButtonWasPressed &&
      currentTime - DebounceTimer > DebounceTime)
  {
    // Button has changed state
    StopResetButtonWasPressed = stopResetButtonIsPressed;
    DebounceTimer = currentTime;

    if (stopResetButtonIsPressed)
    {
      // Just Pressed STOP/RESET
      if (IssRunning)
      {
        // Pausing the timer
        IssRunning = false; // Paused
        ElapsedTime += currentTime - LastStartTime;
      }
      else
      {
        // Was not running so reset everything
        ElapsedTime = 0;
        IssRunning = false;
      }
    }
  }

   unsigned long DisplayTime;
  if (IssRunning)
    DisplayTime = ElapsedTime + (currentTime - LastStartTime);
  else
    DisplayTime = ElapsedTime;

  unsigned long hundredths = DisplayTime / 10;
  unsigned long secondss = hundredths / 100;
  unsigned long minutess = secondss / 60;
  int hourss = minutess / 60;
  int clok;

  if (secondss < 100)
    {// Display seconds.hundredths up to 100 seconds, then minutes:seconds
    clok = (secondss % 100) * 100 + (hundredths % 100);
      Serial.println(clok);
}
  else if (minutess < 100)
  {  // Display minutes:seconds up to 100 minutes, then hours/minutes
    clok = (minutess % 100) * 100 + (secondss % 60);
    Serial.println(clok);}
  else{
    clok = (hourss % 100) * 100 + (minutess % 60);
    Serial.println(clok);}

  // Clear all segments before enabling a digit
 

  // Display each digit, right to left
  
    // Peel a digit off the low end of the number
    int digit = clok % 10;
    clok /= 10;

    // Blank the MSD if it is zero
    
    
      // Display the digit on the seven segments
     

    if (secondss < 100)
    {
      // Steady decimal point when showing seconds and hundredths
   
    }
    else if (minutess < 100)
    {
      // Steady colon when showing minutes and seconds

    }
    else
    {
      // Make the colon blink each second
   
    }

    // Turn on the digit briefly

  
}

what dis i miss ?

Why do you have this part in twice?!?

1 Like