From the course: Learning Arduino: Interfacing with Analog Devices

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Understanding the map() function

Understanding the map() function - Arduino Tutorial

From the course: Learning Arduino: Interfacing with Analog Devices

Start my 1-month free trial

Understanding the map() function

- [Instructor] In the previous example, we generated password modulation, using the software. Now if we want to use another external device to change the light intensity of the LED, we use map function. Let's say, I have values from potentiometer that's connected to the Arduino, and I want to use these values to change the light intensity of the LED. These two values are not in the same range. So map function comes in handy in this situations. Map function remaps a number from one range to another. We have fromLow, and fromHigh values, where low is the minimum value of the original range, and high is the maximum value of the original range. ToLow, and tohigh, where the low is the minimum value of the mapped range, and toHigh is the maximum value of the mapped range. The fromValue is the number to be mapped. For example, it could be values read from another sensor, in our case, it's the Potentiometer. And the new mapped value gets saved in another variable, we call it the toValue, and…

Contents