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.
Directly ported/pinched from Arduino reference.
This simple example converts the gamma range from the device orientation event from a floating point between -90 and +90 to an unsigned int (via | 0
) between -5 and +5:
window.addEventListener('deviceorientation', function (event) {
var g = map(event.gamma, -90, 90, -5, 5) | 0;
el.innerHTML = ['\ngamma', g].join(' ');
}, false);