mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
+ version 0.1.05 (0.1.04 experimental only)
+ added back function to "reverse map" + fastMapDemo2 shows usage of 2 FastMaps + fastMapDemo3 shows usage of back function + FASTMAP_LIB_VERSION in PROGMEM
This commit is contained in:
parent
e7316bd15b
commit
93a4857bc4
@ -1,11 +1,14 @@
|
||||
//
|
||||
// FILE: FastMap.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.03
|
||||
// VERSION: 0.1.05
|
||||
// PURPOSE: class implementation of map function - library for Arduino
|
||||
// URL: http://forum.arduino.cc/index.php?topic=276194
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.05 stripped of bit mask experimental code
|
||||
// 0.1.04 add back() - the inverse map
|
||||
// tested with bit mask for constrain code (Perfomance was killed)
|
||||
// 0.1.03 proper name
|
||||
// 0.1.02 squized the code (first public version)
|
||||
// 0.1.01 refactor
|
||||
@ -18,17 +21,20 @@
|
||||
//
|
||||
// PUBLIC
|
||||
//
|
||||
|
||||
void FastMap::init(float in_min, float in_max, float out_min, float out_max)
|
||||
{
|
||||
_in_min = in_min;
|
||||
_in_max = in_max;
|
||||
_out_min = out_min;
|
||||
_out_max = out_max;
|
||||
|
||||
_factor = (out_max - out_min)/(in_max - in_min);
|
||||
_base = out_min - in_min * _factor;
|
||||
|
||||
_backfactor = 1/_factor;
|
||||
_backbase = in_min - out_min * _backfactor;
|
||||
}
|
||||
|
||||
|
||||
float FastMap::constrainedMap(float value)
|
||||
{
|
||||
if (value <= _in_min) return _out_min;
|
||||
|
@ -1,12 +1,12 @@
|
||||
//
|
||||
// FILE: FastMap.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.03
|
||||
// VERSION: 0.1.05
|
||||
// PURPOSE: class implementation of map function - library for Arduino
|
||||
// URL: http://forum.arduino.cc/index.php?topic=276194
|
||||
//
|
||||
// HISTORY:
|
||||
// see fastMap.cpp file
|
||||
// see FastMap.cpp file
|
||||
//
|
||||
|
||||
#ifndef FastMap_h
|
||||
@ -18,9 +18,7 @@
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
#define FASTMAP_LIB_VERSION "0.1.03"
|
||||
|
||||
#define USE_CONSTRAINED_MAP
|
||||
#define FASTMAP_LIB_VERSION (F("0.1.05"))
|
||||
|
||||
class FastMap
|
||||
{
|
||||
@ -28,6 +26,8 @@ public:
|
||||
void init(float in_min, float in_max, float out_min, float out_max);
|
||||
|
||||
float inline map(float value) { return _base + value * _factor; }
|
||||
float inline back(float value) { return _backbase + value * _backfactor; }
|
||||
|
||||
float constrainedMap(float value);
|
||||
float lowerConstrainedMap(float value);
|
||||
float upperConstrainedMap(float value);
|
||||
@ -35,6 +35,7 @@ public:
|
||||
private:
|
||||
float _in_min, _in_max, _out_min, _out_max;
|
||||
float _factor, _base;
|
||||
float _backfactor, _backbase;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
44
libraries/FastMap/examples/fastMapDemo2/fastMapDemo2.ino
Normal file
44
libraries/FastMap/examples/fastMapDemo2/fastMapDemo2.ino
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// FILE: fastMapDemo2.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.02
|
||||
// PURPOSE: demo of FastMap class ==> a faster map function
|
||||
// DATE: 2014-11-02
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include "FastMap.h"
|
||||
|
||||
FastMap CtoF;
|
||||
FastMap FtoC;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("Start fastMapDemo2\nlib version: ");
|
||||
Serial.println(FASTMAP_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
CtoF.init(0, 100, 32, 212);
|
||||
FtoC.init(32, 212, 0, 100);
|
||||
|
||||
float f = FtoC.map(163);
|
||||
Serial.print(f);
|
||||
Serial.print(char(223));
|
||||
Serial.println('C');
|
||||
|
||||
float c = CtoF.map(f);
|
||||
Serial.print(c);
|
||||
Serial.print(char(223));
|
||||
Serial.println('F');
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
52
libraries/FastMap/examples/fastMapDemo3/fastMapDemo3.ino
Normal file
52
libraries/FastMap/examples/fastMapDemo3/fastMapDemo3.ino
Normal file
@ -0,0 +1,52 @@
|
||||
// FILE: fastMapDemo3.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.00
|
||||
// PURPOSE: demo of FastMap class ==> a faster map function
|
||||
// DATE: 2014-11-02
|
||||
// URL: http://forum.arduino.cc/index.php?topic=276194
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include "FastMap.h"
|
||||
|
||||
FastMap CtoF;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("Start fastMapDemo3\nlib version: ");
|
||||
Serial.println(FASTMAP_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
CtoF.init(0, 100, 32, 212);
|
||||
|
||||
float f = CtoF.map(163);
|
||||
Serial.print(f);
|
||||
Serial.print(char(176));
|
||||
Serial.println('F');
|
||||
|
||||
float c = CtoF.back(f);
|
||||
Serial.print(c);
|
||||
Serial.print(char(176));
|
||||
Serial.println('C');
|
||||
|
||||
f = CtoF.map(163, CONSTRAIN_UPPER);
|
||||
Serial.print(f);
|
||||
Serial.print(char(176));
|
||||
Serial.println('F');
|
||||
|
||||
c = CtoF.back(f, CONSTRAIN_BOTH);
|
||||
Serial.print(c);
|
||||
Serial.print(char(176));
|
||||
Serial.println('C');
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user