Sheco_dev / Mbed 2 deprecated RF_BLDC_FUTABA

Dependencies:   mbed Servo Pulse1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Map.cpp Source File

Map.cpp

00001 #include "Map.h"
00002 //#include "mbed.h"
00003 
00004 float map(float in, float inMin, float inMax, float outMin, float outMax) {
00005   // check it's within the range
00006   if (inMin<inMax) { 
00007     if (in <= inMin) 
00008       return outMin;
00009     if (in >= inMax)
00010       return outMax;
00011   } else {  // cope with input range being backwards.
00012     if (in >= inMin) 
00013       return outMin;
00014     if (in <= inMax)
00015       return outMax;
00016   }
00017   // calculate how far into the range we are
00018   float scale = (in-inMin)/(inMax-inMin);
00019   // calculate the output.
00020   return outMin + scale*(outMax-outMin);
00021 }