diff --git a/speedclock.ino b/speedclock.ino index 2345aa5..08c52a8 100644 --- a/speedclock.ino +++ b/speedclock.ino @@ -250,26 +250,38 @@ void loop(void) { //calculate the run_time and switch to WAIT run_time = (radio_data.topbuttonpressedtime - running_time_offset) - start_time; runner_run_time = runner_start_time - run_time; - timer_new_state = TIMER_WAIT; + delay(10); + if(digitalRead(CANCELBUTTON_IN) != CANCELBUTTON_PRESSED){ + timer_new_state = TIMER_WAIT; + } break; case TIMER_FAIL: //fail start case .... failSequence(); run_time = 99999; runner_run_time = runner_start_time - start_time; - timer_new_state = TIMER_WAIT; + delay(10); + if(digitalRead(CANCELBUTTON_IN) != CANCELBUTTON_PRESSED){ + timer_new_state = TIMER_WAIT; + } break; case TIMER_CANCELLED: // what to do in chancel mode ? run_time = 99999; runner_run_time = runner_start_time - start_time; - timer_new_state = TIMER_WAIT; + delay(10); + if(digitalRead(CANCELBUTTON_IN) != CANCELBUTTON_PRESSED){ + timer_new_state = TIMER_WAIT; + } break; case TIMER_TIMEDOUT: // time out run_time = millis() - start_time; runner_run_time = runner_start_time - start_time; - timer_new_state = TIMER_WAIT; + delay(10); + if(digitalRead(CANCELBUTTON_IN) != CANCELBUTTON_PRESSED){ + timer_new_state = TIMER_WAIT; + } break; case TIMER_WAIT: // disable interrupt if not already done @@ -439,20 +451,24 @@ void startSequence(void) Serial.print("Start time is: "); Serial.println(start_time); // this is sequence of usually three tones after a wait time 1sec , in between the tones there is also a delay of 1 sec. Each tone is 200ms seconds long, except the last + update_statemessage(timer_new_state); if(timer_new_state == TIMER_RUNNING){ delay(STARTSEQ_STARTPAUSE_MS); } // first tone + update_statemessage(timer_new_state); if(timer_new_state == TIMER_RUNNING){ tone(PIEZO_PIN, STARTSEQ_TON_1_2_FREQUENCY,STARTSEQ_TON_1_2_LENGTH_MS ); delay(STARTSEQ_TONEPAUSE_MS); } //second tone + update_statemessage(timer_new_state); if(timer_new_state == TIMER_RUNNING){ tone(PIEZO_PIN, STARTSEQ_TON_1_2_FREQUENCY,STARTSEQ_TON_1_2_LENGTH_MS ); delay(STARTSEQ_TONEPAUSE_MS); } //third tone + update_statemessage(timer_new_state); if(timer_new_state == TIMER_RUNNING){ tone(PIEZO_PIN, STARTSEQ_TON_3_FREQUENCY,STARTSEQ_TON_3_LENGTH_MS ); delay(STARTSEQ_TON_3_LENGTH_MS); @@ -476,10 +492,12 @@ void false_start_isr(void) // this will save the time when the runner is really started Serial.println("** Interrupt service routine started: false_start_ISR **"); runner_start_time = millis(); - if((timer_state == TIMER_STARTED) & (timer_new_state == TIMER_STARTED)){ + if((timer_state == TIMER_STARTED) & (timer_new_state == TIMER_RUNNING)){ timer_new_state = TIMER_FAIL; - detachInterrupt(digitalPinToInterrupt(FAILSTARTBUTTON_IN)); noTone(PIEZO_PIN); + Serial.println("** Interrupt service routine detected false_start. Set new state to TIMER_FAIL **"); + update_statemessage(timer_new_state); + detachInterrupt(digitalPinToInterrupt(FAILSTARTBUTTON_IN)); } else { if((timer_state == TIMER_RUNNING) | (timer_new_state == TIMER_RUNNING) ){ // disable this interrupt;