The concept of mapping a range should be clear by this code example in C explained
// map a value(inputlow to inputhigh) to the range(outputlow to outputhigh)
Code:
int16 map(int16 val, int16 inpl, int16 inph, int16 outl, int16 outh){
int32 tmp=MAX(val,inpl)-inpl; // tmp = (maximum of Val and inputlow) - inputlow
tmp *= (outh-outl); // tmp = tmp * (outputhigh - outputlow)
tmp /= (inph-inpl); // tmp = tmp / (inputhigh - inputlow)
tmp += outl; // tmp = tmp + outputlow
return MIN(tmp,outh); // return the lower of tmp or outputhigh
}
Bookmarks