2016-03-26 00:47:20 +01:00
|
|
|
# Map
|
|
|
|
|
2016-06-30 20:53:13 +02:00
|
|
|
Remaps the specified value from one range to another. This function
|
|
|
|
maps the value of ``from low`` to the value of ``to low``, the value
|
|
|
|
of ``from high`` to the value of ``to high``, and intermediate values
|
|
|
|
to intermediate values.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-06-30 20:53:13 +02:00
|
|
|
This function does not constrain values to the ranges, because
|
|
|
|
out-of-range values are sometimes intended and useful. If you need to
|
|
|
|
limit a range, you can use the ``Math.clamp`` function before or after
|
|
|
|
calling this function.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```sig
|
|
|
|
pins.map(0, 0, 4, 0, 1023);
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
|
2016-06-30 20:53:13 +02:00
|
|
|
* ``value``: a [number](/reference/types/number) that specifies the value to map
|
2016-07-19 00:51:28 +02:00
|
|
|
* ``fromLow``: a [number](/reference/types/number) that specifies the lower bound of the origin interval
|
|
|
|
* ``fromHigh``: a [number](/reference/types/number) that specifies the upper bound of the origin interval
|
|
|
|
* ``toLow``: a [number](/reference/types/number) that specifies the lower bound of the target interval
|
|
|
|
* ``toHigh``: a [number](/reference/types/number) that specifies the upper bound of the target interval
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
## Example
|
|
|
|
|
2016-06-30 20:53:13 +02:00
|
|
|
This example maps the value read from the analog pin `P0` to an LED
|
|
|
|
coordinate between `0` and `4`.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
2016-11-10 22:08:45 +01:00
|
|
|
let value1 = pins.analogReadPin(AnalogPin.P1)
|
2016-03-26 00:47:20 +01:00
|
|
|
let index = pins.map(value1, 0, 1023, 0, 4)
|
|
|
|
led.plot(0, index)
|
|
|
|
```
|
|
|
|
|
|
|
|
### See also
|
|
|
|
|
2016-04-13 17:27:45 +02:00
|
|
|
[analog read pin](/reference/pins/analog-read-pin)
|
2016-03-26 00:47:20 +01:00
|
|
|
|