I am having an issue with an equation in arduino where the output never seems to match what I'm looking for. I keep getting 1, 10, 100 & other #'s I don't expect. I am trying to get something along these lines:
9.31, 6.42, 4.77, 3.93, 3.28, 2.79 (Gear Ratios)
Any suggestions to a better equation that will give the expected results? In the end I want to do some type of compare and get 1-6 for the above gear ratios
Here's the equation
temp = (RPM*81)/(MPH*1056);
sLCD.print(temp,2);
Heres the data types
unsigned int RPM;
unsigned int MPH;
float temp = 0;
nkotbox:
In the end I want to do some type of compare and get 1-6 for the above gear ratios
I suggest you don't put the gear ratios in the code.
A better way to do it would be to put the mid-point between adjacent gear ratios in an array. If you're representing your speed as floating point mph-per-rpm values, then it would be an array of floats.
To find the most likely gear for a given input ratio you iterate through the array until you find the first element that is greater than (or less than, if you start from the other end) your target value. The array index then tells you which gear the input ratio is closest to.
and I was still getting 100, 110, 11 - strange values
Im displaying the RPM and MPH data already so I think those values are ok.
In 4th gear (3.93) I was going 38mph at ~1800rpm's
Per the equation that should equal 3.63 but the display showed 100
It was steady on 100 in 1st
110 in 2nd
10 or 11 in 3rd
then 100 in 4th
err....... :~
16 * 1609 = 25744 so:MPH = (RAWSPD * 125UL) /25744;
I don't know, but I would imagine that casting a fixed number (i.e. not a variable) is unneccessary. The compiler should know how to treat them.
and I was still getting 100, 110, 11 - strange values
Im displaying the RPM and MPH data already so I think those values are ok.
In 4th gear (3.93) I was going 38mph at ~1800rpm's
The variable temp needs to be a float type as well, it is obvious that it is not.
lesson learned. I thought variables temp &TEMP were different in arduino but when I changed temp to Gear, it works as planned with the change I noted in an earlier post. I noted the temp gauge acting funny on a ride which is why I thought to change the name.
I will look thru the code, maybe I typed a temp somewhere in the temp gauge function.