From the course: Learning Arduino: Pulse Width Modulation

Unlock the full course today

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

Using the map function

Using the map function - Arduino Tutorial

From the course: Learning Arduino: Pulse Width Modulation

Start my 1-month free trial

Using the map function

- The Map Function is a powerful tool in your Arduino arsenal. Map scales one range of linear values to another range. This allows you to precisely align two value sets. You can see this idea in action on a thermometer. 0 degrees Celsius and 32 degrees Fahrenheit represent the same actual temperature, just in different systems. If you wanted to use an analog input to control the brightness of an LED, you would need to use the map function or you would lose most of the resolution of the input. Analog inputs read values from 0 to 1023. The analogWrite function takes values from 0 to 255. If you were to write this statement in a block of code, the LED would change in brightness as you adjust the analog input but as soon as your input value surpasses 255, the counter resets. If your input value is 256, it would look like the LED is off. At 510, the LED would be at full bightness again. It will loop like this as the value increases. The LED will not get any brighter and you lose the…

Contents