Pages: [1]   Go Down
Author Topic: Not Displaying decimal information  (Read 515 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am running a sketch where I am trying to capture and display on the LCD the High and Low temperatures. The following works ok, except the High & Low values have no decimal information. It displays like this:

A:22.9
H:24
L:22

Code:
int HighTempA = 0.1;
int LowTempA = 100;
void loop(){
   
  lcd.setCursor(0, 0);
  lcd.print("A:");
  sensors.requestTemperatures();
  lcd.print(sensors.getTempCByIndex(0), 1);
 
  if (HighTempA < sensors.getTempCByIndex(0)) HighTempA = sensors.getTempCByIndex(0);
  lcd.setCursor(0, 1);
  lcd.print("H:");
  lcd.print(HighTempA, 1);
 
  if (LowTempA > sensors.getTempCByIndex(0)) LowTempA = sensors.getTempCByIndex(0);
  lcd.setCursor(0, 2);
  lcd.print("L:");
  lcd.print(LowTempA, 1);
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried both 1, & 0.1. Makes no difference in the final display on LCD.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

He just told you. You need to use float and not int.
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1259
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

INTEGERS (int) are whole numbers only (no decimals).
FLOATING POINT (float) numbers include a decimal component.

If you want floating point you need to declare a variable as float, not int.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you all for the nudge in the right direction, I got it working by changing out my int statements.
Logged

Pages: [1]   Go Up
Jump to: