Professional Documents
Culture Documents
8-2 - Mapping and The Map Function
8-2 - Mapping and The Map Function
A fraction.
5 10
x=6
The concept of mapping: connect two number lines
Input Range Output Range
1023 maps to 255
1023
512 128
0
A realistic example 145 x
An analogRead() function call gives
------- = ----
you a value in the range of 0-1023 - 1023 255
You want to convert that to the range
of 0-255
outputValue=map(inputValue,0,1023,0,255);
The map() function returns an integer value to be
assigned to the outputValue variable.
Especially useful when you don’t always start at 0
Analog input is in the 0-1023 range
512 maps to 98
180
0 maps to 16
512 98
16
0
In conclusion: the map() function
Syntax: