GY-63_MS5611/libraries/MultiMap/README.md

71 lines
2.5 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/MultiMap/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-12-22 06:10:05 -05:00
[![Arduino-lint](https://github.com/RobTillaart/MultiMap/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/MultiMap/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/MultiMap/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/MultiMap/actions/workflows/jsoncheck.yml)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/MultiMap/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/MultiMap.svg?maxAge=3600)](https://github.com/RobTillaart/MultiMap/releases)
2021-12-22 06:10:05 -05:00
2020-11-27 05:20:37 -05:00
# MultiMap
Arduino library for fast non-linear mapping or interpolation of values
2021-05-28 07:39:42 -04:00
2020-11-27 05:20:37 -05:00
## 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.
2021-12-22 06:10:05 -05:00
This is done by the map function which does a linear interpolation.
This means in code:
2021-01-29 06:31:58 -05:00
```cpp
2020-11-27 05:20:37 -05:00
output = C1 + input * C2
```
2021-01-29 06:31:58 -05:00
2020-11-27 05:20:37 -05:00
As C1 and C2 are to be calculated Arduino has the **map()** that calculates the
two variables runtime from two given mappings.
2021-01-29 06:31:58 -05:00
```cpp
2020-11-27 05:20:37 -05:00
output = map(input, I1, I2, O1, O2):
```
2021-12-22 06:10:05 -05:00
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.
2020-11-27 05:20:37 -05:00
2021-12-22 06:10:05 -05:00
**out = Multimap(value, input, output, size)** needs two equal sized arrays of reference 'points',
**input\[\]** and **output\[\]**, it looks up the
2020-11-27 05:20:37 -05:00
input value in the input\[\] array and if needed it linear interpolates between two
points of the output\[\] array.
2021-12-22 06:10:05 -05:00
- The **input\[\]** array must have increasing values,
2020-11-27 05:20:37 -05:00
there is no such restriction for the **output\[\]** array.
2021-01-29 06:31:58 -05:00
- **Multimap()** automatically constrains the output to the first and last value in the **output\[\]** array.
2020-11-27 05:20:37 -05:00
2021-05-28 07:39:42 -04:00
2020-11-27 05:20:37 -05:00
## Operation
See examples
Please note the fail example as this shows that in the intern math overflow can happen.
2021-05-28 07:39:42 -04:00
2021-12-22 06:10:05 -05:00
## Future
2022-11-18 09:09:05 -05:00
#### must
- improve documentation
#### should
- Investigate class implementation
- performance / footprint
- less parameter passing
#### could
2021-12-22 06:10:05 -05:00
- flag if input value was "IN_MIN" < input < "IN_MAX",
now it is constrained without user being informed.
- extend unit tests
2022-11-18 09:09:05 -05:00
#### wont
2021-12-22 06:10:05 -05:00
- should the lookup tables be merged into one array of pairs?
- you cannot reuse e.g. the input array then. (memory footprint)
2020-11-27 05:20:37 -05:00