Pages: [1]   Go Down
Author Topic: DS18B20 - Round Temperature  (Read 881 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 407
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All,
I'm using DS12B20, with the example I've the temperatura displayed like this :

12.23

20.37

etc etc

I would like to round the temperature for example see:

12.20

20.40

Is possible ? Thanks for the information,

Gnux
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 89
Posts: 3452
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is http://playground.arduino.cc/Code/PrintFloats any help ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Sr. Member
****
Karma: 2
Posts: 407
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ciao UKHeliBob,
Thanks you for the link, I've play a little bit with it ... but I would like print on my display and not on Serial ...

But is not possible to pass printFloat() function to LCD.print() function ...

any other ideas ?

I was thing to convert in string and then take left string could be possible ?

Regards,
Andrea
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which LCD library are you using? Does it derive from the Print class?
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 407
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
i'm using LiquidCrystal.h

Regards,
Gnux
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12425
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

round the number e.g. by moving to integer domain.

pseudo code
Code:
float temp =12.34
int t = temp * 10 + 0.5;  // t = 123   (.9)  t is temp in tenths
print t/10;  // integer part
print .
print t%10;  //decimal part
print 0;

(if temp < 0 code might differ slightly)
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From LiquidCrystal.h:
Code:
class LiquidCrystal : public Print {
So, LCD.print(someFloat, 1);
will show someFloat on the LCD rounded to one decimal place.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12425
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The OP wants a trailing zero smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Sr. Member
****
Karma: 2
Posts: 407
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Guys for the suggest,
I will try and then I'll let you know ...

Have nice week end,
Gnux
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 407
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes It's working with the round suggest by Paul !

Thanks you again,
Regards,
Gnux
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 89
Posts: 3452
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does it round or does it truncate ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12425
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

from print.cpp

Code:
// Round correctly so that print(1.999, 2) prints as "2.00"
  double rounding = 0.5;
  for (uint8_t i=0; i<digits; ++i)
    rounding /= 10.0;

rounding it does
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: