need help

how do i make start/stop button in my project?

unsigned long startTime = millis();
    for (unsigned long elapsed = 0; elapsed < delay_timer; elapsed = millis() - startTime) {
      lightDigit1(numbers[digit1]);
      delay(5);
      lightDigit2(numbers[digit2]);
      delay(5);

my project is 2 digit 7 segment shotclock.

lordarbor:
how do i make start/stop button in my project?

Get a button and wire it in the line carrying power to the board. When you press the button it applies power and the board starts. When you release the button it removes power and the board stops.

Or perhaps the first step would be to get a better, more exact definition of exactly what this button should do and how. If you want it to work with some code you already have then you should probably also provide that.

here my whole code am i still trying all what i got.

// Setting up the pins

// Segments that make each number when lit:
// 0 => -FEDCBA
// 1 => ----BC-
// 2 => G-ED-BA
// 3 => G--DCBA
// 4 => GF--CB-
// 5 => GF-DC-A
// 6 => GFEDC-A
// 7 => ----CBA
// 8 => GFEDCBA
// 9 => GF-DCBA

// Arduino digital pins used to light up
// corresponding segments on the LED display
#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
#define F 7
#define G 8

// Pins driving common cathodes
#define CA1 9
#define CA2 10

// Pins for stop button and start button
#define Startbutton 12
#define Stopbutton 13
//setting the state of the buttons
int Startstate = 0;
int Stopstate = 0;
int delay_timer = 1000;
//setting the default value of the display
int digit1 = 2;
int digit2 = 4;

// Pins for A B C D E F G, in sequence
const int segs[7] = { A, B, C, D, E, F, G };

// Segments that make each number
const byte numbers[10] = { 0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, 0b1101101,
                           0b1111101, 0b0000111, 0b1111111, 0b1101111
                         };

void setup() {
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(CA1, OUTPUT);
  pinMode(CA2, OUTPUT);
  pinMode(Startbutton, INPUT_PULLUP);
  pinMode(Stopbutton, INPUT_PULLUP);

}

void loop() {
  Startstate = digitalRead(Startbutton);
  Stopstate = digitalRead(Stopbutton);
  if (Startstate == LOW) {
    delay_timer = 1000;
  }

  
  if (Stopstate == LOW) {
    delay_timer = 99999;
  }

 
     unsigned long startTime = millis();
    for (unsigned long elapsed = 0; elapsed < delay_timer; elapsed = millis() - startTime) {
      lightDigit1(numbers[digit1]);
      delay(5);
      lightDigit2(numbers[digit2]);
      delay(5);


  }
  if ( digit2 > 0) {
    digit2 = digit2 - 1;
  }
  else {
    digit2 = 9;
    digit1 = digit1 - 1;
  }
  if (digit1 < 0) {
    digit2 = 4;
    digit1 = 2;
  }




}

void lightDigit1(byte number) {
  digitalWrite(CA1, LOW);
  digitalWrite(CA2, HIGH);
  lightSegments(number);
}

void lightDigit2(byte number) {
  digitalWrite(CA1, HIGH);
  digitalWrite(CA2, LOW);
  lightSegments(number);
}

void lightSegments(byte number) {
  for (int i = 0; i < 7; i++) {
    int bit = bitRead(number, i);
    digitalWrite(segs[i], bit);
  }
}

OK. You still need to define what this code and this button is supposed to do. You should describe what the code you have now does and how that differs from what you want.

I just want todo if i press the stop button the timer will stop and if i press the start button the timer will resume

lordarbor: I just want todo if i press the stop button the timer will stop and if i press the start button the timer will resume

ok, so do like I said and just wire it as a power button so when you press the start button it turns on the power and when you press the stop button it turns off the power.

Or should you be a little more specific. Coding is an awfully exacting science. You gotta be perfectly exactly clear with yourself about your requirements before you can even start to write the code. Once you can describe it precisely, the code will practically write itself. But as long as you are talking about it in vague terms you're doomed.

lordarbor: I just want todo if i press the stop button the timer will stop and if i press the start button the timer will resume

Maybe start by telling us what part of your program you want to stop and start.

A common way to do the sort of thing you mention is to have a variable - let's call it timerMayRun - and use the stop button to set it to false and the start button to set it to true.

Then your timer routine can check whether the variable is true (in which case the counting can continue) or false.

...R