GY-63_MS5611/libraries/MultiMap
2022-11-18 15:09:05 +01:00
..
.github add funding.yml 2022-08-03 21:56:07 +02:00
examples 0.1.5 MultiMap 2021-12-22 12:10:05 +01:00
test 0.1.6 MultiMap 2022-11-18 15:09:05 +01:00
.arduino-ci.yml 0.1.6 MultiMap 2022-11-18 15:09:05 +01:00
CHANGELOG.md 0.1.6 MultiMap 2022-11-18 15:09:05 +01:00
keywords.txt 0.1.5 MultiMap 2021-12-22 12:10:05 +01:00
library.json 0.1.6 MultiMap 2022-11-18 15:09:05 +01:00
library.properties 0.1.6 MultiMap 2022-11-18 15:09:05 +01:00
LICENSE 0.1.5 MultiMap 2021-12-22 12:10:05 +01:00
MultiMap.h 0.1.6 MultiMap 2022-11-18 15:09:05 +01:00
README.md 0.1.6 MultiMap 2022-11-18 15:09:05 +01:00

Arduino CI Arduino-lint JSON check License: MIT GitHub release

MultiMap

Arduino library for fast non-linear mapping or interpolation of values

Description

In Arduino applications often the value of a sensor is mapped upon a more usable value. E.g. the value of analogRead() is mapped onto 0 .. 5.0 Volt. This is done by the map function which does a linear interpolation. This means in code:

    output = C1 + input * C2

As C1 and C2 are to be calculated Arduino has the map() that calculates the two variables runtime from two given mappings.

    output = map(input, I1, I2, O1, O2):

In many cases when there is no linear mapping possible, as the 'points' are not on a single straight line. One needs non-linear math to calculate the output, Multimap() just simulates that.

out = Multimap(value, input, output, size) needs two equal sized arrays of reference 'points', input[] and output[], it looks up the input value in the input[] array and if needed it linear interpolates between two points of the output[] array.

  • The input[] array must have increasing values, there is no such restriction for the output[] array.
  • Multimap() automatically constrains the output to the first and last value in the output[] array.

Operation

See examples

Please note the fail example as this shows that in the intern math overflow can happen.

Future

must

  • improve documentation

should

  • Investigate class implementation
    • performance / footprint
    • less parameter passing

could

  • flag if input value was "IN_MIN" < input < "IN_MAX", now it is constrained without user being informed.
  • extend unit tests

wont

  • should the lookup tables be merged into one array of pairs?
    • you cannot reuse e.g. the input array then. (memory footprint)