outputValue =
map
(sensorValue,
0
,
1023
,
0
,
255
);
Description:
Re-maps a number from one range to another. That is, a value of
fromLow would get mapped to
toLow, a value of fromHigh to toHigh, 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
constrain()
function may be used either before or after this function,
if limits to the ranges are desired.
Note that the “lower bounds” of either range may be larger or smaller than the “upper bounds” so
the
map()
function may be used to reverse a range of numbers, for example
y = map(x, 1, 50, 50, 1);
The function also handles negative numbers well, so that this example
y = map(x, 1, 50, 50, -100);
is also valid and works well.
The map() function uses integer math so will not generate fractions, when the math might indicate
that it should do so. Fractional remainders are truncated and are not rounded or averaged.
Syntax:
map(
value, fromLow, fromHigh, toLow, toHigh)
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.
toLow: the lower bound of the value’s target range.
toHigh: the upper bound of the value’s target range.
Mapping light sensor analog signal(0 to 1023)to the brightness value of LED(0 to 255).
Keep equal and potentiometer after mapping the value of the time. The Map has five parameters,
which in turn is: to map the original value, the original value of the minimum value, original value
maximum, minimum value after the mapping, mapping the maximum. In this way, the data
returned by the sensor can be mapped from its original value of 0-1023 to 0-255.
analogWrite(ledPin,
255
-outputvalue);
33
Grove Beginner Kit For Arduino
®
Содержание Grove Beginner Kit
Страница 1: ...Grove Beginner Kit For Arduino User Manual ...
Страница 63: ...62 Grove Beginner Kit For Arduino ...