// Sonar sensor range computation/display program. int x; task main () { int range; SetSensor (SENSOR_1, SENSOR_LIGHT); SetUserDisplay (x, 0); OnFwd(OUT_A+OUT_C); start drive; while(true) { range = (SENSOR_1/2) + 6; x = range; Wait(5); } } task drive() { until(x == 50); Off(OUT_A+OUT_C); repeat(5) { PlaySound (SOUND_CLICK); Wait(30); } OnFwd(OUT_A+OUT_C); until(x == 40); Off(OUT_A+OUT_C); repeat(4) { PlaySound (SOUND_CLICK); Wait(30); } OnFwd(OUT_A+OUT_C); until(x == 30); Off(OUT_A+OUT_C); repeat(3) { PlaySound (SOUND_CLICK); Wait(30); } OnFwd(OUT_A+OUT_C); until(x == 20); Off(OUT_A+OUT_C); repeat(2) { PlaySound (SOUND_CLICK); Wait(30); } OnFwd(OUT_A+OUT_C); until(x == 10); Off(OUT_A+OUT_C); repeat(1) { PlaySound (SOUND_CLICK); Wait(30); } OnFwd(OUT_A+OUT_C); until(x == 6); Off(OUT_A+OUT_C); }