function mathRandomInt(a, b) { if (a > b) { // Swap a and b to ensure a is smaller. var c = a; a = b; b = c; } return Math.floor(Math.random() * (b - a + 1) + a); } while(true) { if (await BTSmart_I1_mini_switch.isClosed()) { await Utility.sleep(mathRandomInt(1, 4) * 1000); await BTSmart_M1_motor.setSpeed(512, Motor.CW); await Utility.sleep(800); await BTSmart_M1_motor.stop(); await Utility.sleep(1000); await BTSmart_M2_motor.setSpeed(512, Motor.CCW); await Utility.sleep(300); await BTSmart_M2_motor.setSpeed(80, Motor.CCW); while (!(await BTSmart_I1_mini_switch.isOpen())) { await Utility.sleep(10); } await BTSmart_M1_motor.stop(); await Utility.sleep(500); await BTSmart_M2_motor.setSpeed(150, Motor.CCW); while (!(await BTSmart_I2_mini_switch.isClosed())) { await Utility.sleep(10); } await BTSmart_M2_motor.stop(); await BTSmart_M1_motor.setSpeed(512, Motor.CCW); await Utility.sleep(500); await BTSmart_M1_motor.stop(); } await Utility.sleep(10); }