task main () { long encA = 0; long encB = 0; long encC = 0; ubyte motorStatus = 0; string motorAstatus; string motorBstatus; string motorCstatus; eraseDisplay(); // Initialise all the internal variables HDMMUXinit(); // Reset the encoders. This can be done individually or all at once. // You should do this at the start of your program. HDMMotorEncoderResetAll(HDMMUX); // You can specify the type of braking that should be used when the motors // are sent the stop command. The default is to use brake. HDMMotorSetBrake(mmotor_S1_1); HDMMotorSetFloat(mmotor_S1_2); HDMMotorSetFloat(mmotor_S1_3); // Specify a target for the motors to run to. This can be number of // rotations, seconds or degrees (encoder count). Rotations and seconds // may be specified in increments of 0.01. HDMMotorSetRotationTarget(mmotor_S1_1, 4.50); HDMMotorSetTimeTarget(mmotor_S1_2, 2.50); HDMMotorSetEncoderTarget(mmotor_S1_3, 1000); // Tell the motors to start moving. HDMMotor(mmotor_S1_1, 50); HDMMotor(mmotor_S1_2, 50); HDMMotor(mmotor_S1_3, 50); while (true) { // Retrieve the motor-MUX's status info and encoder counts HDMMUXreadStatus(HDMMUX, motorStatus, encA, encB, encC); // Use the HDMMotorBusy() function to see if a motor is busy or idle. motorAstatus = HDMMotorBusy(mmotor_S1_1) ? "busy" : "idle"; motorBstatus = HDMMotorBusy(mmotor_S1_2) ? "busy" : "idle"; motorCstatus = HDMMotorBusy(mmotor_S1_3) ? "busy" : "idle"; // Display the info. nxtDisplayTextLine(5, "A: %5d (%s)", encA, motorAstatus); nxtDisplayTextLine(6, "B: %5d (%s)", encB, motorBstatus); nxtDisplayTextLine(7, "C: %5d (%s)", encC, motorCstatus); wait1Msec(5); } }
task main () { long encA = 0; long encB = 0; long encC = 0; long timer = 0; ubyte motorStatus = 0; string motorAstatus; bool done = false; eraseDisplay(); // Initialise all the internal variables HDMMUXinit(); // Reset the encoders. This can be done individually or all at once. // You should do this at the start of your program. HDMMotorEncoderResetAll(HDMMUX); // You can specify the type of braking that should be used when the motors // are sent the stop command. The default is to use brake. HDMMotorSetBrake(mmotor_S1_1); // Specify a motor 1 to run for 2.5 seconds. HDMMotorSetTimeTarget(mmotor_S1_1, 2.50); // Tell the motors to start moving. HDMMotor(mmotor_S1_1, 50); // Reset the timer time1[T1] = 0; // Give the motor time to get started wait1Msec(50); while (!done) { // Retrieve the motor-MUX's status info and encoder counts HDMMUXreadStatus(HDMMUX, motorStatus, encA, encB, encC); // Use the HDMMotorBusy() function to see if a motor is busy or idle. motorAstatus = HDMMotorBusy(mmotor_S1_1) ? "busy" : "idle"; if (!HDMMotorBusy(mmotor_S1_1) && timer == 0) { timer = time1[T1]; nxtDisplayTextLine(0,"Time: %dms", timer); done = true; } // Display the info. nxtDisplayTextLine(6, "B: %5d (%s)", encB, motorAstatus); EndTimeSlice(); } wait1Msec(5000); }