/* * Ping * ==== * Adapted from a program by Dave Chen and Simen Svale Skogsrud * * This program assumes that the light sensor is on IN_2 and * that it points in the same direction as the infrared connection * on the robot. It beeps when the robot gets close to an obstacle. * This is done by repeatedly sending IR messages. These cause a * large fluctuation in light intensity. * * This is a nice mechanism to find a close by wall without bumping * in to it. */ #define THRESHOLD 200 // Making this larger decreases the distance int lastlevel; task Ping() // Constantly test whether there is a high fluctuation { SetSensor(SENSOR_2,_SENSOR_CFG(SENSOR_TYPE_LIGHT, SENSOR_MODE_RAW)); lastlevel = 0; while(true) { SendMessage(0); if(lastlevel > SENSOR_2) { // Close to something PlaySound(1); Wait(30); } lastlevel = SENSOR_2; lastlevel -= THRESHOLD; } } task main() { start Ping; }