map arduino code example

Example 1: map arduino

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.
  
Example:
map(val, 0, 255, 0, 1023);

Example 2: arduino map function

long map(long x, long in_min, long in_max, long out_min, long out_max)
 {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Tags:

Cpp Example