Skip to content

adbancroft/avr-fast-map

Repository files navigation

Build Unit Tests

avr-fast-map: a faster implementation of the Arduino map() function.

The standard Arduino map function is implemented using division of signed long integers. This is a very slow operation on AVR, since there is no hardware divider. The fast_map function provided by this library can be much faster. E.g. mapping a uint8_t input to a uint8_t output range is ~10x faster.

Exact speedup varies depending on data types & number ranges.

Using the library

Installation

The library is available in both the Arduino Library and PlatformIO Library registries.

The library can also be cloned & included locally or included directly from GitHub (if your tooling supports it).

Code

  1. #include <avr-fast-map.h>
  2. Replace calls to map with calls to fast-map.

The code base is compatible with all platforms: non-AVR builds compile down to the map function.

About

A faster implementation of the Arduino map() function

Topics

Resources

Stars

Watchers

Forks

Contributors