@@ -16,8 +16,10 @@ Arduino library for mapping a float to a number of bits.
1616
1717## Description
1818
19- Map2bits is an ** experimental** library which can be used to map a float
20- value to a number of HIGH bits in an 32 bits integer..
19+ ** Experimental**
20+
21+ Map2bits is an experimental library which can be used to map a float
22+ value to a number of HIGH bits in an 32 bits integer.
2123The float value can be the result of a calculation or measurement from a
2224sensor, e.g. temperature, humidity, light, distance, direction or pressure.
2325
@@ -36,7 +38,7 @@ In short many devices to drive or applications to think of.
3638As always, feedback is welcome.
3739
3840
39- #### Related
41+ ### Related
4042
4143Other mapping libraries
4244
@@ -54,15 +56,25 @@ Other mapping libraries
5456#include " map2bits.h"
5557```
5658
57- #### Functions
59+ ### Constructor
5860
5961- ** map2bits()** Constructor, defines a default mapping of (0..100 => 10)
6062- ** uint8_t init(float in_min, float in_max, uint32_t bits)** defines the mapping
6163input range and how many bits output should be generated.
64+
65+ ### Mapping
66+
67+ The output of the ** map()** functions is a bit mask and can be used to drive e.g. a led bar etc.
68+
6269- ** uint32_t map(float value)** maps value to an uint32_t with the appropriate
6370number of bits set. These are constrained by the number of bits set in ** init()** .
64-
65- The output of ** map()** is a bit mask and can be used to drive e.g. a led bar etc.
71+ - ** uint16_t map16(float value)** maps value to an uint16_t with the appropriate
72+ number of bits set. These are constrained by the number of bits set in ** init()** .
73+ Slightly faster (~ 2.5%).
74+ - ** uint32_t map32(float value)** equals map().
75+ - ** uint64_t map64(float value)** maps value to an uint64_t with the appropriate
76+ number of bits set. These are constrained by the number of bits set in ** init()** .
77+ Typical only used if one wants more than 32 bits.
6678
6779
6880## Operation
@@ -85,15 +97,33 @@ See examples.
8597
8698Indicative performance measured with the ** map2bits_performance.ino** example.
8799Performance depends on input chosen, platform support of float, and if
88- values are constrained (out range) or interpolated (in range)
100+ values are constrained (out range) or interpolated (in range).
101+ Run tests on your own board to get the numbers.
102+
103+ Note: times in microseconds per call
104+ Note: UNO at 16 MHz, ESP32 at 240 MHz
105+ Note: out of range == 33% in range, 66% out range
106+ Note: map() == map32()
107+
108+ | board | function | in range | out range | notes |
109+ | :--------:| :----------:| :----------:| :-----------:| :--------|
110+ | UNO R3 | map16 | 45.22 | 22.08 |
111+ | UNO R3 | map32 | 46.28 | 22.49 |
112+ | UNO R3 | map64 | 49.00 | 23.60 | for > 32 bits
113+ | | | | |
114+ | ESP32 | map16 | 0.42 | 0.24 |
115+ | ESP32 | map32 | 0.41 | 0.23 |
116+ | ESP32 | map64 | 0.52 | 0.33 | for > 32 bits
117+
118+
119+ ## Polarity
89120
90- Note: time in microseconds per call
91- Note: UNO at 16 MHz, ESP32 at 240 MHz
121+ The user can swap polarity by inverting with ~
92122
93- | board | map - in range | map - out range | notes |
94- | :-------: | :---------------: | :-----------------: | :-------- |
95- | UNO | 45.35 us | 22.20 us | 33% in range, 66% out range
96- | ESP32 | | | to do
123+ ``` cpp
124+ x = ~mb.map( 42 ); // x = 0xFFFFFFF0 =>
125+ x = ~mb.map( 42 ) & 0xFFFF // x = 0x0000FFF0 optional mask.
126+ ```
97127
98128
99129## Future
@@ -105,29 +135,25 @@ Note: UNO at 16 MHz, ESP32 at 240 MHz
105135
106136#### Should
107137
108- - extend the idea to applications
109- - add examples
110- - optimize
138+ - add examples / applications
139+ - investigate optimize
140+ - do we need map16() => optimizer does clean up.
111141
112142#### Could
113143
114- - test other boards
115- - ** map2bits64(value) ** uint64_t for 33 - 64 bits output
116- - might need printHelpers
117- - ** map2bitsDouble(value) ** Double version (input range + precision)
118- - ** map2bitsDouble64(value) ** Double version (33 - 64 bits output)
119- - uint32_t input version
144+ - map logarithmic (map exponent)
145+ - MSB/LSB 00000011 <> 0000110000 ? (SIZE = 6)
146+ - reverse from CRC library
147+
148+ #### Wont
149+
120150- map2DAC?
121151 - maps a range to analogWrite()..
122152 - separate class.
123153- polarity 0001 <> 1110 ?
124154 - ~ operator
125- - MSB/LSB 0001 <> 1000 ?
126- - reverse from CRC library
127-
128-
129- #### Wont
130-
155+ - map16(uint32_t) map32(uint32_t) map64(uint32_t) => accuracy float is sufficient
156+ - map2bitsDouble(value), map2bitsDouble64(value) Double version (input range + precision)
131157
132158## Support
133159
0 commit comments