So this is a bit screwy using this 16x2 LCD. I want to display the temperature in the following format (for example): 78.35 degrees.
I’m using a Dallas One Wire thingy - and I get good data using the serial monitor. For example, when I open the serial monitor, I get the following: 78.35. Perfect.
Using the 16x2 display, when I use the code: lcd.print(temperature), I get: 78
Now, I realize, that for the 16x2 display, I have to put my own “.” between the first two (or three) digits, followed by a lcd.print(“.”) and then the last two digits.
My question, is how do I get the just the last two digits from my variable “temperature”?
I envision the code to be something like this:
lcd.print("Temp is: ");
lcd.print(temperature);
lcd.print(".");
lcd.print(temperature); // just need the last two digits of the variable here
Got the degree symbol, that's 337. As far as the accuracy, yah, I suppose you're right, so let's just get it to a tenth. Lemme try your suggestion, although I think I already tried this.
int val = temperature * 100;
int dec = val % 100;
lcd.print(val / 100);
lcd.printByte('.');
if (dec < 10) {
lcd.printByte('0');
}
lcd.print(dec);
lcd.printByte(0xDF);
Actually, that gave me "78.00223." So, I switched back to what I had for degree symbol. Anyhow, still not working as I am just getting 78.00 for values other than .00
My code exceeds maximum length. Most of the code is a motion clock, and it works great. I was just adding the temp sensor. And I agree, two decimal points exceeds tolerance, but I'd like to at least have one decimal point.
Well, got it to work. Thanks for the snippet of code.
When I used the
temperature=(sensors.getTempFByIndex(0));
int val = temperature*100;
that didn't work. For some strange reason, I had to use int val = (sensors.getTempFByIndex(0)) * 100
In other words, when I used my variable in the *100, I kept getting values ending in 00 (81.29=8100). Only when I replaced my variable did I get the proper 8129, which the snippet could then work with.
I'm laughing as I write this, but yes, I defined it as an int.
I tried to include the full code as I've seen many before me reprimanded for not doing the same, but it exceeded the message limitation (9000), and I didn't know what to include or not include.