173 return 1; |
173 return 1; |
174 } |
174 } |
175 return 0; |
175 return 0; |
176 } |
176 } |
177 |
177 |
|
178 void startbutton(void) { |
|
179 // start button press active |
|
180 if (mode == 0) { |
|
181 mode = 1; // set wait for race start mode |
|
182 reset_vars(); |
|
183 LED(1, 1); |
|
184 LED(2, 1); |
|
185 LED(3, 1); |
|
186 LED(4, 1); |
|
187 LED(5, 1); |
|
188 RS232_puts_p(prepare); |
|
189 } else if (mode == 1) { |
|
190 // Initiate race countdown |
|
191 sysclk.value = 0; |
|
192 countdown = 5; |
|
193 countdown_loops = COUNTDOWN_DELAY; |
|
194 mode = 2; |
|
195 LED(1, 0); |
|
196 LED(2, 0); |
|
197 LED(3, 0); |
|
198 LED(4, 0); |
|
199 LED(5, 0); |
|
200 RS232_puts_p(countdownstart); |
|
201 } |
|
202 } |
|
203 |
178 ISR ( USART_RXC_vect ) { |
204 ISR ( USART_RXC_vect ) { |
179 uint8_t tmp; |
205 uint8_t tmp; |
180 char c = UDR; |
206 char c = UDR; |
181 |
207 |
182 // check for buffer overflow |
208 // check for buffer overflow |
600 |
632 |
601 // read in button presses |
633 // read in button presses |
602 btn_start = (PIN(SW_START_PORT) & _BV(SW_START)); |
634 btn_start = (PIN(SW_START_PORT) & _BV(SW_START)); |
603 if (old_start != btn_start) { |
635 if (old_start != btn_start) { |
604 // start button changed |
636 // start button changed |
605 if (btn_start == 0) { |
637 if (btn_start == 0) startbutton(); |
606 // start button press active |
|
607 if (mode == 0) { |
|
608 mode = 1; // set wait for race start mode |
|
609 reset_vars(); |
|
610 LED(1, 1); |
|
611 LED(2, 1); |
|
612 LED(3, 1); |
|
613 LED(4, 1); |
|
614 LED(5, 1); |
|
615 RS232_puts_p(prepare); |
|
616 } else if (mode == 1) { |
|
617 // Initiate race countdown |
|
618 sysclk.value = 0; |
|
619 countdown = 5; |
|
620 countdown_loops = COUNTDOWN_DELAY; |
|
621 mode = 2; |
|
622 LED(1, 0); |
|
623 LED(2, 0); |
|
624 LED(3, 0); |
|
625 LED(4, 0); |
|
626 LED(5, 0); |
|
627 RS232_puts_p(countdownstart); |
|
628 } |
|
629 } |
|
630 old_start = btn_start; |
638 old_start = btn_start; |
631 } |
639 } |
632 |
640 |
633 if (mode==3) { |
641 if (mode==3) { |
634 // RACE START! |
642 // RACE START! |