/* ==================================================================== * sonar.c * * Test the mindsensors sonar ranging device. * * Motors on A and C * Sonar on input 2 * * Copyright: Gary Harkin * 2005 * * ===================================================================== */ #include #include #include #include #include #include #define SONARSENS SENSOR_2 static void display_range (int r) { cls(); lcd_number (r, unsign, e0); } int main(int argc, char *argv[]) { int x; /* * Set the sensor passive so that it can recalibrate. Takes about 1 second. */ ds_passive (&SONARSENS); sleep (2); /* * Now make it active and put it in percent mode for reading. */ ds_active (&SONARSENS); /* Testing code. For hard surfaces, it calibrates to a raw value of about 5 for a 6 inch separation. It maxes out at about 80, but drops off in accuracy rapidly after about 6 feet. */ while (1) { x = LIGHT(SONARSENS); display_range (x); sleep (1); } return 0; }