From the course: Learning Arduino: Pulse Width Modulation

Unlock the full course today

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

Solution: Understanding the math behind the map function

Solution: Understanding the math behind the map function - Arduino Tutorial

From the course: Learning Arduino: Pulse Width Modulation

Start my 1-month free trial

Solution: Understanding the math behind the map function

- How did it go? Were you able to map all of the values? Let's take a quick look at the math to solve these problems. The first value on the handout is 17. 17 divided by 1023, is .0166, or 1.66 percent. To keep the math simple, I'll round that up to two percent. Two percent of 255 is 5.1, so the arduino will map that value to roughly five percent. The next value is 58. 58 divided by 1023 is .0566, or 5.66 percent, which I will round up to six percent. Six percent of 255 is 15.3, so the arduino will map that value to roughly 15. You can see the next three values in this table as well. With each value increase, the scale number increases. The final five values are calculated the same way. When you are working with various inputs and outputs, it can be helpful to make tables like these as reference. They can be incredibly helpful when testing for logic bugs.

Contents