Many times I’ll mock up my Arduino formulas in a spreadsheet before I start building a sketch. One of the more complicated Arduino commands to emulate is the MAP command.
The Arduino code:
height = map(adc, 171, 512, 12, 0);
In Excel becomes:
= (adc-in_min)*(out_max-out_min) / (in_max-in_min) + out_min
The following emulates a voltage divider that converts a fluid level of a container to gallons. It uses a reverse map as decreasing resistance of the sensor means increasing depth.
Become the Maker you were born to be. Try Arduino Academy for FREE!