1.2 KiB
1.2 KiB
Map
Re-maps a number from one range to another. That is, a value of from low
would get mapped to to low
, a value of from high
to to high
, values in-between to values in-between, etc.
Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The math->clamp
function may be used either before or after this function, if limits to the ranges are desired.
pins.map(0, 0, 4, 0, 1023);
Parameters
value
: Number - the value to mapfrom low
: Number - lower bound of the origin intervalfrom high
: Number - upper bound of the origin intervalto low
: Number - lower bound of the target intervalto high
: Number - upper bound of the target interval
Example
Map the value read from the analog pin P0
to an LED index between 0
and 4
.
let value1 = pins.analogReadPin(AnalogPin.P0)
let index = pins.map(value1, 0, 1023, 0, 4)
led.plot(0, index)