scale defaults to a percentage-range output, so you can get away with:
scale(sensorReading, 100, 500);
If v is outside of the input range, it will likewise be outside of the output range.
Use scaleClamped to clip value to range.
If inMin and inMax are equal, outMax will be returned.
An easing function can be provided for non-linear scaling. In this case
the input value is 'pre scaled' using the function before it is applied to the
output range.
Scales
v
from an input range to an output range (akamap
)For example, if a sensor's useful range is 100-500, scale it to a percentage:
scale
defaults to a percentage-range output, so you can get away with:If
v
is outside of the input range, it will likewise be outside of the output range. Use scaleClamped to clip value to range.If inMin and inMax are equal, outMax will be returned.
An easing function can be provided for non-linear scaling. In this case the input value is 'pre scaled' using the function before it is applied to the output range.