//PING Sonar //equations were taken from here and not independently verified: //http://www.societyofrobots.com/member_tutorials/node/174 //http://www.societyofrobots.com/robotforum/index.php?topic=5123.msg40008 //http://www.societyofrobots.com/robotforum/index.php?topic=4656.30 //uses timer0 int sonar_Ping() { #define PINGPIN 0 // assign a pin to the Ping Sensor #undef DDR #undef PIN #define DDR DDRC #define PORT PORTC #define PIN PINC PORT_ON(DDR, PINGPIN); // Switch PingPin to OUPUT // ------Trigger Pulse-------------- PORT_OFF(PORT, PINGPIN); // Bring PingPin low before starting trigger pulse delay_us(2); // Wait for 2 microseconds PORT_ON(PORT, PINGPIN); // Bring PingPin High for 5us according to spec sheet. delay_us(5); // Wait for 5 microseconds PORT_OFF(PORT, PINGPIN);; // Bring PingPin Low and standby //--------End Trigger Pulse--------------------- FLIP_PORT(DDR, PINGPIN); // Switch PingPin to INPUT loop_until_bit_is_set(PIN, PINGPIN); // Loop until the the PingPin goes high (macro found in sfr_def.h) //clears timer, reset overflow counter reset_timer0(); //reset timer 0 loop_until_bit_is_clear(PIN, PINGPIN); // Loop until the the PingPin goes low (macro found in sfr_def.h) //read timer0's overflow counter //255 is count before overflow, dependent on clock return (get_timer0_overflow()*255+TCNT0) * 2.068965517;//elapsed time x conversion }
static void echo(double *ping_value,const uint8_t pingpin) { /*Round-trip-time, unit microseconds*/ uint16_t elapsed_time; /* ------Trigger Pulse--------------------------*/ PORT_ON(DDR, pingpin); PORT_OFF(PORT, pingpin); _delay_us(2); PORT_ON(PORT, pingpin); _delay_us(5); PORT_OFF(PORT, pingpin); /*--------End Trigger Pulse---------------------*/ /*--------Meassure pulse------------------------*/ FLIP_PORT(DDR, pingpin); loop_until_bit_is_set(PIN, pingpin); reset_timer_0(); loop_until_bit_is_clear(PIN, pingpin); /*--------Stop Meassure pulse-------------------*/ /* MAXCOUNTER is dependent on timer */ elapsed_time = (tot_overflow * MAXCOUNTER) + TCNT0; /*Simple band-pass filter*/ if (elapsed_time >= ping_distance_max) *ping_value = 0; else if (elapsed_time <= ping_distance_min) *ping_value = 0; else *ping_value = (elapsed_time * TO_CM); _delay_us(250); }
void flash_locked_led(void) { unlocked_led(0); // turn off unlocked led locked_led(1); // Turn on Locked led for (unsigned int w=0;w<=5;w++) { // Flash Locked led FLIP_PORT(PORTC,5); delay_ms(150); }//end for locked_led(1); // Turn on Locked led , make sure its on }
void toggle_noconn_led(void){ FLIP_PORT(PORTC,6); }
void toggle_locked_led(void){ FLIP_PORT(PORTC,5); }
void toggle_unlocked_led(void){ FLIP_PORT(PORTC,4); }
void toggle_repair_led(void){ FLIP_PORT(PORTC,7); }
void toggle_pin_led(void){ FLIP_PORT(PORTC,3); }
void toggle_hold_led(void) { FLIP_PORT(PORTC,2); }
void toggle_Lite(void) { FLIP_PORT(PORTD,5); }