// Radar version 2 #define ANGLE 1000 #define SPEED 65 #define DOTTED_LINES 1 int Radar[100]; int Position; /////////////////////////////////////////////////////////////////////// void Initialize_screen( void) { int i; ClearScreen(); for (i=0; i<100; i++) { if (Radar[i]>4 && Radar[i]<128) CircleOut( i, Radar[i]/2, 3, DRAW_OPT_NORMAL); Radar[i] = 0; if (i & DOTTED_LINES) { PointOut( i, 16); PointOut( i, 32); PointOut( i, 48); } } } ////////////////////////////////////////////////////////////////////// task Turn_radar() { ResetTachoCount( OUT_A); while (true) { Initialize_screen( ); RotateMotor( OUT_A, +SPEED, ANGLE); Initialize_screen( ); RotateMotor( OUT_A, -SPEED, ANGLE); } } /////////////////////////////////////////////////////////////////////// task Radar_unit() { int Distance; SetSensorLowspeed(IN_4); while (true) { Distance = SensorUS( IN_4); Position = MotorTachoCount(OUT_A)*100/ANGLE; if (Position<0) Position = 0; Position = (Position<100)? Position : 99; Radar[ Position] = Distance; if (Distance>4 && Distance<128) CircleOut( Position, Distance/2, 2, DRAW_OPT_FILL_SHAPE); LineOut(0,0,Position,0); LineOut(Position,0,99,0,DRAW_OPT_CLEAR); printf("%5d", Distance); Wait( 50); } } /////////////////////////////////////////////////////////////////////// task main() { Precedes(Turn_radar,Radar_unit); ClearScreen(); }