Creating a function and using the results.
RS_Jim Posts: 1,732
I have the following formula:
It works when I use the formula for each calculation. But when I attempt to create a PUB function, Iam not getting the correct answers. The in/out values are constants with different values passed by the calling object. In_val is passed from the out of an adc object.
How do I write that such that I can call it passing the 5 parameters and using the map_val calculated?
I use this method in the P2 (with slight changes for the P1 [gte/lte operators])
I use the if-else-elseif structure to skip unnecessary * and / instructions for the P1 (not a problem for the P2).
For example, if you wanted to scale a 0-3.3v input to a new range of 0 to 100 (%), you would do this:
This assumes that you're analog input is in millivolts (I do this in my P2 ADC object).
You can even flip output value polarity. My friend, John, makes camera platforms and we sometimes do things like this with a joystick or center-sprung pot.
Thanks Jon, I will give that a try
Installed your code and as usual, it worked grreat.
I suspected it would. Good luck with your project.