
164 Make: Wearable Electronics
To accomplish this, there is a very useful Arduino function called map(). It
looks like this:
map(value, fromLow, fromHigh, toLow, toHigh)
In this function, value is the value you would like to map, fromLow and
fromHigh are the low and high end of the original data set, and toLow and
toHigh are the low and high values of the mapped data set. If you were
to map the full range of analog input (0–1023) to the full range of analog
output (0 to 255), you’d use the following line of code:
map(lightSensorValue, 0, 1023, 0, 255)
A complete sketch looks something like this:
/*
Make: Wearable Electronics
Mapping example
*/
// initialize ...