Skip to main content

Posts

Showing posts from 2017

Arduino map function decimal places (floating point numbers)

The programming library available with the Arduino has an interesting interpolation function, the  map  function. Sadly, it returns only integers. As you might want to interpolate floating point numbers for some instrumentation routines, this limitation with integers may lend you to some low-resolution results. Fortunately, Arduino supports method overloading, and we can rewrite another  map  function to support floating point numbers. The new  map  function could be like this: float map(int x, double in_min, double in_max, double out_min, double out_max){  return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min; }