Can someone help with this code.
In the setup I need to calibrate a sensor(mv1) so what ever value it returns( lets say 300 at the start) will give the variable ppo1 a value of 100.
So the calibration value would be 300/100=3 or multi1=mv1/100
Later if the sensor gives a value of 600 then ppo1 should then =200 so mv1/multi=200
All seems pretty straight forward but the math does not work and I guess it has to do with decimal places or something.
Can someone please explain how this code should be written.
setup()
mv1=analogRead(PPO1pin);
mult1=(mv1/100); // puts sensor value into PPO#pin then works out the calibration multiplier.
OK. I have tried it a different way and it seems to work much better.
But is it best?
What is the highest number you can work with ( 32767?) and what is the lowest (0?)?
From what I understand you cant use decimals? so 0.1 cant be used and 9/4= 2 not 2.25??
I want PPO to = 100 at start up based on what the value of mv1 is.
So if mv1=500 at start up PPO will be 100.( mult1= 500/100)
Later when mv1 changes to 250 PPO will = 50
If mv1 changes to 1000 PPO will then =200
Like wise upon start up if mv1 = 200 PPO will be 100 ( mult1= 200/100)
when mv1 rises to 1000 PPO will be 500
What is the highest number you can work with ( 32767?) and what is the lowest (0?)?
An "int" has the range -32768 to +32767, an "unsigned int" has the range 0 to 65535,
a "long" goes -2 147 483 647 to +2 147 483 648 and an "unsigned long" 0 to 4 294 967 295.
Packhorse:
What is the highest number you can work with ( 32767?) and what is the lowest (0?)?
From what I understand you cant use decimals? so 0.1 cant be used and 9/4= 2 not 2.25??
AWOL has given you the highest and lowest values of the integral types. If you want to use decimals, use type 'float' instead. So, whereas 9/4 is indeed 2, 9.0/4.0 is 2.25, as is ((float)9)/((float)4).
I think he/she need to calibrate first.
Maybe to an ambient reading or some kind of calibration medium for a sensor.
Perhaps this: ( 'unsigned int', close enough? )
I see your solution is similar to mine which seems to work well.
So basically increasing the values so that any decimals have very little effect on the math while keeping the values low enough to not exceed 32767.
I see your solution is similar to mine which seems to work well.
So basically increasing the values so that any decimals have very little effect on the math while keeping the values low enough to not exceed 32767.
I just changed your solution so mult1 would always equal a whole number so it has half a chance of being exact. The values would be less than 65,535 'unsigned int'. If mv1 = 1023 then multiplying it by 50 will =51150.
Multiply by <32 in you want to use int.
Your first solution (and mine) will work with float. I can see why float is slower than int calculations but I'm not sure why
Floating point numbers are not exact, and may yield strange results when compared.