Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Servo Pulse1
Map.cpp
- Committer:
- kyucheol
- Date:
- 2019-12-27
- Revision:
- 0:7663c81cdf71
File content as of revision 0:7663c81cdf71:
#include "Map.h"
//#include "mbed.h"
float map(float in, float inMin, float inMax, float outMin, float outMax) {
// check it's within the range
if (inMin<inMax) {
if (in <= inMin)
return outMin;
if (in >= inMax)
return outMax;
} else { // cope with input range being backwards.
if (in >= inMin)
return outMin;
if (in <= inMax)
return outMax;
}
// calculate how far into the range we are
float scale = (in-inMin)/(inMax-inMin);
// calculate the output.
return outMin + scale*(outMax-outMin);
}