Scale

Syntax:

    integer_variable = Scale (value , fromLow , fromHigh , toLow , toHigh [, calibration] )

Command Availability:

Available on all microcontrollers.   The parameters are:

value: the number to scale

fromLow: the lower bound of the value’s current range

fromHigh: the upper bound of the value’s current range

toLow: the lower bound of the value’s target range

toHigh: the upper bound of the value’s target range

calibration: optional calibration offset value.

Explanation:

Scales, re-maps, a number from one range to another.   That is, a value of fromLow would gets scaled to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.

The method does not constrain values to within the integer range returned, because out-of-range values are sometimes intended and useful.

Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the scale() method may be used to reverse a range of numbers, for example:

    my_newvalue  = scale ( ReadAD10(An0) , 0, 1023, 135, 270)

The method also handles negative integer numbers well, so that this example:

    my_newvalue = scale(ReadAD(An0), 0, 255, 50, -100);

This method is similar to the Ardunio Map() function.