Skip to content

Commit

Permalink
Merge pull request #17 from code-dot-org/round-scaled-sensor-values
Browse files Browse the repository at this point in the history
Round scaled sensor values
  • Loading branch information
fisher-alice authored Oct 19, 2022
2 parents 1e48dda + 385be4e commit 60e49f0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ class Sensor extends Withinable {
},
scaled: {
get() {
let mapped;
let constrain;
let mapped, constrain;

if (state.scale && raw !== null) {
if (options.type === "digital") {
Expand All @@ -206,7 +205,8 @@ class Sensor extends Withinable {
}

mapped = Fn.fmap(raw, this.range[0], this.range[1], state.scale[0], state.scale[1]);
constrain = Fn.constrain(mapped, state.scale[0], state.scale[1]);
// Code.org: round scaled sensor values
constrain = Fn.constrain(Math.round(mapped), state.scale[0], state.scale[1]);

return constrain;
}
Expand Down

0 comments on commit 60e49f0

Please sign in to comment.