mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
Fixing #1505: WeDo2 motor power between 0-30ish doesn't power the motor.
This commit is contained in:
parent
7a7134e23c
commit
d7440f882d
1 changed files with 10 additions and 2 deletions
|
@ -226,7 +226,15 @@ class WeDo2Motor {
|
||||||
* @param {int} value - this motor's new power level, in the range [0,100].
|
* @param {int} value - this motor's new power level, in the range [0,100].
|
||||||
*/
|
*/
|
||||||
set power (value) {
|
set power (value) {
|
||||||
this._power = Math.max(0, Math.min(value, 100));
|
const p = Math.max(0, Math.min(value, 100));
|
||||||
|
// Lego Wedo 2.0 hub only turns motors at power range [30 - 100], so
|
||||||
|
// map value from [0 - 100] to [30 - 100].
|
||||||
|
if (p === 0) {
|
||||||
|
this._power = 0;
|
||||||
|
} else {
|
||||||
|
const delta = 100 / p;
|
||||||
|
this._power = 30 + (70 / delta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue