Go Down

Topic: Not Displaying decimal information (Read 688 times) previous topic - next topic

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: [Select]
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);
}

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

Lsnyman

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

marco_c

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.
Arduino Libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy