Hello everybody, this is my first post.
I manage to use my Arduino like a simpe "voltmeter" and interfacing with a 16x2 display.
I done all the hardware and the lcd correctly working with the included library LiquidCrystal, read an analog value and related it to the Vref of 5V.. now the problem is the format to display the value.
I use the lcd.print function, but in the reference it is not specified if it works with float values... I try it and it Works! but it display 2 significant digits.
For example, if the value is 12.3423 it display 12.34.. it can be ok, but I don't need such a precision and I want to save space on the display, so for me 1 single digit is enough (practically I want that the print on the display is 12.3).
How can I make this thing?
Thank you very much! it Works.. the reference is not updated.
It is very powerful this library because, not only define the number of significant digits, but automatically rounds the value.
robtillaart: @liudr
from the liquidCrystal.cpp : class LiquidCrystal : public Print
So LCD implements print, and print class supports printing floats - so it should work ...
Rob, I read the print.h. You're right the print now has (float,digit). I wish same has happened to the sprintf float support.
The AVR libc function sprintf() does support floating point. It is the arduino IDE that is the problem.
With the AVR libc as it it currently supplied, you have change the linker option to enable the floating point
version of of the xxprintf() functions.
Currently, there is no way to set the linker options with the official arduino IDE.
There was an old forum post, (which I was unable to locate now )
that gave the patches as well as included a pre build IDE that allowed the compiler and linker options
to be configured in a file. I used it and it was great for changing optimizations and turning on/off warnings.
You could always blow off the IDE and use makefiles.....
where:
floatvar -float variable
StringLengthIncDecimalPoint -length of the string that will be created
numVarsAfterDecimal -number of digits after the deimal point to print
charbuf -array to store the results
Here's the thread where I display Fuel Rail Pressure, Turbo Boost & Voltage in single decimal floats: Arduino Freematics OBD