A library that maps one range onto another range.
Dependents: Heiko Simran_Servo_2410 HYDRO-pH-BASIC NucleoBoard_1 ... more
Revision 1:dad975e2e150, committed 2016-09-28
- Comitter:
- Kerneels Bezuidenhout
- Date:
- Wed Sep 28 04:02:59 2016 +0200
- Parent:
- 0:f274b178a2d4
- Commit message:
- Initial version
Changed in this revision
Map.cpp | Show annotated file Show diff for this revision Revisions of this file |
Map.hpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Map.cpp Wed Sep 28 01:44:45 2016 +0000 +++ b/Map.cpp Wed Sep 28 04:02:59 2016 +0200 @@ -0,0 +1,14 @@ +#include "Map.hpp" + +Map::Map(float inMin, float inMax, float outMin, float outMax) +{ + _inMin = inMin; + _inMax = inMax; + _outMin = outMin; + _outMax = outMax; +} + +float Map::Calculate(float inVal) +{ + return ( (inVal - _inMin)*(_outMax - _outMin)/(_inMax - _inMin) + _outMin ); +}
--- a/Map.hpp Wed Sep 28 01:44:45 2016 +0000 +++ b/Map.hpp Wed Sep 28 04:02:59 2016 +0200 @@ -0,0 +1,34 @@ +#ifndef MAP_H +#define MAP_H + +#include "mbed.h" + +/** + * A library that maps one range (inMin -> inMax) to another (outMin -> outMax) + * + * @author CA Bezuidenhout + */ +class Map +{ +public: + /** + * @param inMin : Minimum value of input range + * @param inMax : Maximum value of input range + * @param outMin : Minimum value of output range + * @param outMax : Maximum value of output range + */ + Map(float inMin, float inMax, float outMin, float outMax); + + /** + * Map inVal onto the output range + * + * @param inVal : A value in the input range to be mapped onto the output range + * @returns A value in the output range + */ + float Calculate(float inVal); +private: + float _inMin,_inMax; + float _outMin,_outMax; + +}; +#endif