 # Display two different things on one LCD line?

Hi all, I am programming my LCD screen and have a questions. Basically I used the tutorials I found online but they display the data on two different lines (see attached code). The result looks like this Temp F 100Deg

what I would like it to do is all fall on one line like this

Temp F ... 100Deg

Can someone tell me how to modify the code to do that?

Thanks

`````` // Display Temperature in C
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 100.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
// ----------------
lcd.print("Temp F ");
lcd.setCursor(6, 0);
lcd.print(tempF);
``````

Just get rid of the the set cursor...

There might be a problem if the floating point number is too big. Also, I don't know if the LCD print library handles floating point numbers. What happens if you do this:

``````float tempF = tempC * 9.0 / 5.0 + 32.0;

int tempApprox = (int) tempF;  // This dumps any fractional part

// ----------------
lcd.print("Temp F ");          // Space after the 'F'
lcd.print(tempApprox );        // Don't need decimal value.
``````

econjack: There might be a problem if the floating point number is too big. Also, I don't know if the LCD print library handles floating point numbers. What happens if you do this:

``````float tempF = tempC * 9.0 / 5.0 + 32.0;
``````

int tempApprox = (int) tempF;  // This dumps any fractional part

// ---------------- lcd.print("Temp F ");          // Space after the 'F' lcd.print(tempApprox );        // Don't need decimal value.

It does. Just specify the number of trailing digits, like this:

``````float tempF = tempC * 9.0 / 5.0 + 32.0;

lcd.print("Temp F:");
lcd.print(tempApprox, 0 );        // no decimal digit.
// or lcd.print(tempApprox, 1 );        // one decimal digit.
``````

It handles rounding better. 19.9998 degrees is printed as 19 as an integer, a rounded double will correctly print as 20.

Spoolx: Hi all, I am programming my LCD screen and have a questions. Basically I used the tutorials I found online but they display the data on two different lines (see attached code). The result looks like this Temp F 100Deg

what I would like it to do is all fall on one line like this

Temp F ... 100Deg

`````` // Display Temperature in C
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 100.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
// ----------------
lcd.print("Temp F ");
lcd.setCursor(6, 0);
lcd.print(tempF);
``````

You don't say what display you have, I assume it's a 16x2 and what you want will fit. The library should have no difficulty printing floats. If it does, change it for the standard one, which definitely doesn't.

You don't need to put

lcd.print("Temp F ");

in the loop. It can go in Setup as you are better off only printing it once. You can do the same with Deg - like ...............1 16 lcd.print("Temp deg F";

and drop the value in the middle

I submit it would be better to use

lcd.setCursor(9, 0);

With what you have, thereby placing the data in a more sensible position and still have room for a pretty big number. That is what I do using a DS18B20, which returns a float with two decimal places. For a range of 0.01-99.99C, you can print " " first for values less than 10, thereby ensuring the decimal point always stays in line, and there are no stray 1/100ths from previous readings.