Sport timer with start procedure and foot switch for false start - how to?

Hi,

Total noob, bad English etc. My apologies...

OK, so my daughter is building a sport timing system project for two "runners" (two tracks). There are two tracks, two timing displays and two finish buttons but they both start at the signal, actually after the starting procedure.

The starting procedure is as follows:

  1. Judge announces the start
  2. First beep (low pitch 200 ms) on 1st sec
  3. Second beep (low pitch 200 ms) on 2nd sec
  4. Third beep (hi pitch 100 ms) on 3rd sec
  5. START

The problem (programming problem) is that runners have to step on the foot switch during this start procedure of 3.1 sec and if they step off and the switch (goes LOW) then ... that poor guy's LEDs, display, beep... Armageddon.

She has no idea (neither have I) how to write code that will do the start procedure while constantly checking the switch status at the same time.

Please help me be a good father. Thanks.

Part of the code (without other buttons, LEDs etc.:

int number = 0;
int startProcDone = 0;

void loop()
{
  startProcedure();
  showNumber(number);
  number++;
  number %= 10000; //Reset number after 9999
  Serial.println(number); //For debugging
  delay(10);
}

void startProcedure()
{
    if (startProcDone == 0)
  {
    delay(1000);
    tone(piezoBuzz, 262, 200);
    delay(1000);
    tone(piezoBuzz, 262, 200);
    delay(1000);
    tone(piezoBuzz, 523, 100);
    delay(100);    
    startProcDone = 1;
  }
}

She has no idea (neither have I) how to write code that will do the start procedure while constantly checking the switch status at the same time.

Have a look at Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

Thanks!

I was already replying that I've looked at those examples before posting the question and that they didn't help but then she told me she solved everything with millis(). Shes says she has removed all delays and that she will never use them again.

Kids :wink: