fix: stop motor when power set to 0

When motor power set to 0, the motor stops.
This commit is contained in:
tpsnt 2024-02-09 09:44:55 +08:00 committed by GitHub
parent 7313ce5199
commit ba32baa3c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1375,7 +1375,11 @@ class Scratch3WeDo2Blocks {
this._forEachMotor(args.MOTOR_ID, motorIndex => {
const motor = this._peripheral.motor(motorIndex);
if (motor) {
motor.power = MathUtil.clamp(Cast.toNumber(args.POWER), 0, 100);
const power = MathUtil.clamp(Cast.toNumber(args.POWER), 0, 100);
if (power === 0) {
motor.turnOff();
}
motor.power = power;
motor.turnOn();
}
});