Beginners question

Hi,
I´m a beginner with arduino and i have a question.

I have built a second counter with 2 seven segment displays.
It count from 0 to 99 seconds.
Now i want to add a push button, when i press it the counter should start count and when i release it
the counter should stop.
If i press it again the counter should start counting from zero.

I have tried different solutions but nothing will work for me... :S

Here is the code:

#define A 7
#define B 6
#define C 4
#define D 3
#define E 2
#define F_SEG 8
#define G 9

// Pins driving common anodes
#define CA1 16
#define CA2 10

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

// Segments that make each number
const byte numbers[10] = { 0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010,
0b0000010, 0b1111000, 0b0000000, 0b0010000 };

void setup() {
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F_SEG, OUTPUT);
pinMode(G, OUTPUT);
pinMode(CA1, OUTPUT);
pinMode(CA2, OUTPUT);
}



void loop() {
  for (int digit1=0; digit1 < 10; digit1++) {
  for (int digit2=0; digit2 < 10; digit2++) {
    unsigned long startTime = millis();
    for (unsigned long elapsed=0; elapsed < 1000; elapsed = millis() - startTime) {
      lightDigit1(numbers[digit1]);
      delay(5);
      lightDigit2(numbers[digit2]);
      delay(5);
    }
  }
}
}

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);
}
}

I like the way you've used italics.

Please, please get into the habit of using code tags when posting code.

You can edit them into your post by clicking on "modify"

AWOL:
Please, please get into the habit of using code tags when posting code.

Ooops..
Have now modify my post. :slight_smile:

Now i want to add a push button, when i press it the counter should start count and when i release it
the counter should stop.
If i press it again the counter should start counting from zero.

It sounds like the StateChangeDetection example in the IDE would be helpful to you to detect when a button becomes pressed as opposed to when it is pressed. Keep track of the number of button presses and write code, possibly in separate functions, to do what you want when the button has been pressed a number of times.