Skip to content
Jim Lee edited this page Mar 19, 2020 · 18 revisions

Abstract:

A very common issue one runs across when programming is unit translation and value limiting. You are given some value that covers an arbitrary range and you need to "map" this value to a unit that you are looking for. And, at the same time, limit the range of the inputted data to "sane" values.

That was really wordy, lets try an example. You would like to make a digital volt meter. You have an analog input that gives values from 0 to say.. 1024. Next you need to find what the limits are of your circuit. At your lowest voltage, what number do you read from the analog input? What's your highest voltage reading? This gives us 4 values.

Low voltage - corresponding analog value, analogA.
High voltage - corresponding analog value, analogB.

From this we plug all four into a mapper object.

mapper myMapper(analogA, analogB,lowVoltage,highVoltage);

Now that we have our mapper, we can read analog values and use our mapper object to calculate our voltage values.

linkListObj:

Constructor:

mapper(void);
No parameters, creates a mapper...

Other methods:

`

Clone this wiki locally