Sheco_dev / Mbed 2 deprecated FINAL_BLUE_BLDC_DC

Dependencies:   mbed Servo Pulse1

Committer:
kyucheol
Date:
Fri Dec 27 09:09:04 2019 +0000
Revision:
0:7663c81cdf71
modified codes and  added some explanation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kyucheol 0:7663c81cdf71 1 #include "Map.h"
kyucheol 0:7663c81cdf71 2 //#include "mbed.h"
kyucheol 0:7663c81cdf71 3
kyucheol 0:7663c81cdf71 4 float map(float in, float inMin, float inMax, float outMin, float outMax) {
kyucheol 0:7663c81cdf71 5 // check it's within the range
kyucheol 0:7663c81cdf71 6 if (inMin<inMax) {
kyucheol 0:7663c81cdf71 7 if (in <= inMin)
kyucheol 0:7663c81cdf71 8 return outMin;
kyucheol 0:7663c81cdf71 9 if (in >= inMax)
kyucheol 0:7663c81cdf71 10 return outMax;
kyucheol 0:7663c81cdf71 11 } else { // cope with input range being backwards.
kyucheol 0:7663c81cdf71 12 if (in >= inMin)
kyucheol 0:7663c81cdf71 13 return outMin;
kyucheol 0:7663c81cdf71 14 if (in <= inMax)
kyucheol 0:7663c81cdf71 15 return outMax;
kyucheol 0:7663c81cdf71 16 }
kyucheol 0:7663c81cdf71 17 // calculate how far into the range we are
kyucheol 0:7663c81cdf71 18 float scale = (in-inMin)/(inMax-inMin);
kyucheol 0:7663c81cdf71 19 // calculate the output.
kyucheol 0:7663c81cdf71 20 return outMin + scale*(outMax-outMin);
kyucheol 0:7663c81cdf71 21 }