Skip to content
Snippets Groups Projects
BTSmart_Useless_Machine_2.js 1.05 KiB
Newer Older
ft-Demo's avatar
ft-Demo committed
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);
ft-Demo's avatar
ft-Demo committed
}
ft-Demo's avatar
ft-Demo committed
while(true) {
ft-Demo's avatar
ft-Demo committed
  if (await BTSmart_I1_mini_switch.isClosed()) {
    await Utility.sleep(mathRandomInt(1, 4) * 1000);
ft-Demo's avatar
ft-Demo committed
    await BTSmart_M1_motor.setSpeed(512, Motor.CW);
ft-Demo's avatar
ft-Demo committed
    await Utility.sleep(800);
ft-Demo's avatar
ft-Demo committed
    await BTSmart_M1_motor.stop();
ft-Demo's avatar
ft-Demo committed
    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())) {
ft-Demo's avatar
ft-Demo committed
      await Utility.sleep(10);
    }
    await BTSmart_M1_motor.stop();
ft-Demo's avatar
ft-Demo committed
    await Utility.sleep(500);
    await BTSmart_M2_motor.setSpeed(150, Motor.CCW);
ft-Demo's avatar
ft-Demo committed
    while (!(await BTSmart_I2_mini_switch.isClosed())) {
      await Utility.sleep(10);
    }
    await BTSmart_M2_motor.stop();
    await BTSmart_M1_motor.setSpeed(512, Motor.CCW);
ft-Demo's avatar
ft-Demo committed
    await Utility.sleep(500);
ft-Demo's avatar
ft-Demo committed
    await BTSmart_M1_motor.stop();
ft-Demo's avatar
ft-Demo committed
  }
ft-Demo's avatar
ft-Demo committed
  await Utility.sleep(10);
ft-Demo's avatar
ft-Demo committed
}