I'm using the LiquidCrystal_I2C library by Mario_H and am having trouble getting the desired result. The app is timing events using the millis function and then calculating a floating point number in seconds,
i.e. Lane1ET = (Lane1StopTime - StartTime)/1000.0;
Where Lane1ET is a float, Lane1StopTime and StartTime are unsigned longs.
I'm sending the values to the display like this:
Lane1ET = (Lane1StopTime - StartTime)/1000.0;
lcd.setCursor(0,0);
lcd.print("LANE 1 ");
lcd.print(Lane1ET);
The behavior I'm getting is that only 2 places beyond the decimal are displayed. As my timing interval increases, places are added in front of the decimal but I always have 2 decimal places. I'm trying to display at least to the 3rd decimal place and 4th if possible.
I tried declaring Lane1ET as a char Lane1ET[7] but get a compile error on the first line above.
Any insight into what's going on here would be greatly appreciated.
Thanks, controlmech
How you declaring the variable Lane1StopTime & Start Time. if it is unsigned long int Why you are dividing by 1000.0 floating value. Why can't you divide by 1000 itself???
Just cross check it once
With Lane1ET declared as float, you should be able to use
lcd.print(Lane1ET,3)
lcd.print(Lane1ET,4)
If there is something in the Mario_H library blocking more than two decimal places, consider changing to the F. Malpartida library.
If you have fixed room for e.g. 6 digits including decimal point + sign you need to write your own formatting routine.
something like this
void myPrint(float val)
{
int n = lcd.print((int) val); // decimal part with sign
int digitsLeft = max(6-n,0);
if (digitsleft > 0)
{
long factor = 1;
for (int i=0; i<digitsleft; i++) factor *= 10;
long frac = (val - (int) val) * factor ; // get fraction as long
lcd.print("."); // decimal point
lcd.print(frac);
}
}
Cattledog, once again you have saved the day!
The ,#) at the end of the lcd.print took care of the issue.
Thanks again,
controlmech