Fri, 09 Dec 2011 22:15:50 +0100
pitlane response enter/exit pitlane, led lit when car is in pitlane
pitlane/main.c | file | annotate | diff | comparison | revisions |
--- a/pitlane/main.c Fri Dec 09 22:02:34 2011 +0100 +++ b/pitlane/main.c Fri Dec 09 22:15:50 2011 +0100 @@ -31,6 +31,12 @@ #define PIT_CONNECT_PIN PC3 #define PIT_GROUND_PIN PC2 // low active +#define SENS2_PORT PORTD +#define SENS2_PIN PD5 + +#define LED_PORT PORTB +#define LED_PIN PB5 + // internal analog comparator doesnt work well //#define ANALOG_COMPARATOR 1 @@ -209,6 +215,8 @@ int main(void) { + uint8_t tmp; + // setup data bit timer2 TCCR2 = (1<<CS21) | (1<<WGM21); //divide by 8, set compare match OCR2 = TIMER2_50US; @@ -253,6 +261,10 @@ // setup pitlane output DDR(PIT_PORT) |= _BV(PIT_CONNECT_PIN) | _BV(PIT_GROUND_PIN); + // setup LED + DDR(LED_PORT) |= _BV(LED_PIN); + LED_PORT |= _BV(LED_PIN); // switch LED off + // CONNECT PITLANE TO MAIN TRACK PIT_PORT &= ~_BV(PIT_CONNECT_PIN); PIT_PORT |= _BV(PIT_GROUND_PIN); @@ -324,6 +336,12 @@ } } sens[1].car = 0; + if ( (PIN(SENS2_PORT) & _BV(SENS2_PIN)) != 0 ) { + // set inside status + for (tmp=0; tmp<MAX_SLOTS; tmp++) + slot[tmp].inside = 0; + RS232_puts_p(PSTR("PIT:EXIT\n")); + } if (sens[2].car != sens[2].state) { sens[2].state = sens[2].car; @@ -340,6 +358,11 @@ } } sens[2].car = 0; + // enable LED when car is in pitlane + LED_PORT |= _BV(LED_PIN); + for (tmp=0; tmp<MAX_SLOTS; tmp++) + if (slot[tmp].inside) LED_PORT &= ~_BV(LED_PIN); + } // main loop end };