Reading a temp: how to make a kind of hysteris

I’m reading a temperature by sampling it every 0,25 sec.

The value sent to LCD is the medium value of five measurements.

Well.

But when temperature is around the integers (es. 14.1, 13.9 ) I see a ugly “switch” up/down, down/up of the unit (14,13,14,13 ecc.)

I would make a simple hysteris by increasing the minimun division required to switch the unit.

I.e. if temperature is between [14,5…15,5[ then display 15 and so on…

How I can proceed? What do you think about the following pseudo code? Is there a Better/lighter alternative?

1. Temp <----------- Fetch temperature (two digits after the point)

2. intTemp <-------- Get integer part of Temp

3. if | (Temp-intTemp) | < .5 then 
              TempToDisplay <------- floor(Temp)
   else 
              TempToDisplay <------- ceil(Temp)

Thanks

Did you try make more samples to calculate the average ? you told that was five measurements, maybe it'll be better if you try 10 or 20 measurements ..

Thanks Radamés for the hint.

Now I have 20 samples "time spaced" of 50ms (total 1s refresh for LCD)

Do you think that this delay is ok both for ADC reading that for LCD displaying?

Thanks again

I think it's ok, however if you're measuring fast temperatures changes or you need precision in time, you'll need review this delay!