mapTo01()

Re-maps a number between 0.0 and 1.0. That is, a value of fromLow would get mapped to 0.0, a value of fromHigh to 1.0, values in-between to values in-between, etc.

mapTo01(x, fromLow, fromHigh)

is equivalent to:

mapFloat(x, fromLow, fromHigh, 0, 1)

By default, does not constrain output to stay within the [fromHigh, toHigh] range, because out-of-range values are sometimes intended and useful. In order to constrain the return value within range, use the CONSTRAIN argument as the last parameter:

mapTo01(x, fromLow, fromHigh, CONSTRAIN)

See mapFloat() for more details.

Example

#include <Plaquette.h>

AnalogOut led(9);

void begin() {
}

void step() {
  // Generate a sinusoidal values between -1 and 1.
  float x = sin(seconds());

  // Remap to the range [0, 1] and send to LED.
  mapTo01(x, -1, 1) >> led;
}

Reference

float pq::mapTo01(double value, double fromLow, double fromHigh, uint8_t mode = UNCONSTRAIN)

Re-maps a number to the [0, 1] range.

Parameters:
  • value – the number to map

  • fromLow – the lower bound of the value’s current range

  • fromHigh – the upper bound of the value’s current range

  • mode – set to CONSTRAIN to constrain the return value between toLow and toHigh or WRAP for the value to wrap around

Returns:

the mapped value in [0, 1]

See Also