// Program of Pimousse, weight lifter used for CC9 contest //******************************************************** // Motors A and B power the hoist #define LiftMotor OUT_A+OUT_B // Motor C is used for crane travel #define MoveMotor OUT_C // two rotation sensors monitor the height reached and the distance travelled #define LiftRotSensor SENSOR_1 #define MoveRotSensor SENSOR_3 // Constants defining distances and height. // Note that the lift rotation sensor actually measures hoist turns, // not height. Precision is thus low, as it depends on the // way the cable places on the drum. #define BeginMove 500 #define MaxHeight 3000 #define MaxMove -1300 int Time; task main () { // set sensors SetSensor (LiftRotSensor, SENSOR_ROTATION); SetSensor (MoveRotSensor, SENSOR_ROTATION); ClearSensor (LiftRotSensor); ClearSensor (MoveRotSensor); // initialize time lift stopwatch and display it on the LCD ClearTimer (1); SetUserDisplay (Timer(1), 1); // start weight lifting OnFwd (LiftMotor); while (LiftRotSensor < BeginMove); // The weight is no longer on ground, begin to move OnRev (MoveMotor); // Wait till we reach maximum height while (LiftRotSensor < MaxHeight) { // If we travelled enough, stop moving if (MoveRotSensor < MaxMove) Off (MoveMotor); } // begin lowering the load OnRev (LiftMotor); while (LiftRotSensor > 0) { // If we travelled enough, stop moving if (MoveRotSensor < MaxMove) Off (MoveMotor); } // Ok, we are done. Stop motors! Off(LiftMotor + MoveMotor); // Freeze stopwatch display Time = Timer(1); SetUserDisplay (Time, 1); // and beep! PlaySound (SOUND_DOUBLE_BEEP); until (false); }