#define ROTATION SENSOR_1 #define RESET SENSOR_2 int DISTANCE = 0 ; /* This only works with the RCX 2.0 firmware. */ task main() { SetSensor( RESET, SENSOR_TOUCH ) ; SetSensor( ROTATION, SENSOR_ROTATION ) ; ClearSensor( ROTATION ) ; SelectDisplay ( DISPLAY_USER ); SetUserDisplay( DISTANCE, 2 ) ; while ( true ) { if ( RESET == 1 ) ClearSensor( ROTATION ) ; /* The diameter of the wheel is 3cm, there are 16 * clicks per revolution of the rotation sensor, and * the gearing is 1:3 so one click correponds roughly * to (3 * 3.14) / 48 or approximately .19625cm. * The display assumes two decimal places so the * following should display the distance correctly. */ DISTANCE = 196 * ROTATION ; } }