Go Down

Topic: decimal point in temp reading (Read 2 times) previous topic - next topic

2660

I have pieced this code together to read and average thermistor readings.  It works fine but I am trying to figure out how to show it to one decimal.

output as is = xx F
I would like = xx.x F

Code: [Select]
/*
* Thermistor Function, read thermistor and return an averaged value
*/
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;            // Convert Kelvin to Celcius
Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
//return Temp;

float averageTemp; // create a float to hold running average
for (int i = 1; i < 1000; i++) // start at 1 so we dont divide by 0
    averageTemp += ((Temp - averageTemp)/(float)i); // get next sample, calculate running average
return averageTemp; // return average temperature reading
}

PaulS

That code does not output the temperature. Therefore, no code changes are required IN THAT CODE.

2660


That code does not output the temperature. Therefore, no code changes are required IN THAT CODE.


I suppose it depends on what your definition of output is.  It does RETURN a value...

PaulS

Quote
It does RETURN a value...

Sure, and that value is a double. Therefore, it has, by definition, a fractional part.

That you do not see the fractional part means that whatever code is showing you the value is doing so in a way other than what you want. But, we can't see that code.

2660

Fare enough,

Code: [Select]
vfd.print(int(Thermister(analogRead(1))));

So I am thinking it's the int()?
How do I only display one past the decimal point?

Go Up