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 - Arduino Tutorial
From the course: Learning Arduino: Interfacing with Analog Devices
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
How Arduino generates analog output1m 4s
-
(Locked)
Understanding pulse-width modulation (PWM)2m 8s
-
(Locked)
Understanding the analogWrite function with PWM1m 19s
-
(Locked)
Wire up an LED1m 5s
-
(Locked)
Write code to use PWM with the LED1m 56s
-
(Locked)
Understanding the map() function1m 45s
-
(Locked)
Wiring a potentiometer to control LED1m 13s
-
(Locked)
Coding to control the LED with a potentiometer3m 42s
-
(Locked)
-
-
-