Is it possible to create function to lcd.print multiple variables with one command?
I mean like this:
PrintToFirstRow(,,, , , , , , , , , ,)
instead of this:
lcd.setcursor(0,0);
lcd.print();
lcd.setcursor(3,0);
lcd.print("");
...
I'd like to make my menu code shorter...
The conventional method is a convention for humans. It may be possible to do what you propose, but I wouldn't be surprised if it made no difference after it was compiled for Arduino. It may turn out that all you do is confuse humans.
See the sprintf() function. It is designed to create formatted output.
sprintf() will format the output into a buffer than then printed using print().
A word of warning though, on AVR Arduino boards, floating point is disabled by default.
It can be re-enabled but you have to change the AVR recipe file.
If you are using a Teensy board, it includes a printf() method in the Print class so you
use
lcd.printf("format-string", var, var, ...);
Alternatively you could use the PrintEx library which will add a printf() method to your lcd object.
(or any other object that uses the Print class)
It supports many of the printf formatting strings and also has floating support on the AVR.
It will allow you to use
lcd.printf("format-string", var, var, ....);
--- bill
You also may want to take a look at the streaming library.
It offers C++ style output.
It doesn't offer the formatting capabilities of printf() but it does do the simple output that it looks like you want to do.
http://arduiniana.org/libraries/streaming/
It is very easy to use.
Just include the header file and you get C++ style streaming support.
for example:
lcd.setcursor(0,0);
lcd << aFloat << someText << aLong;
BTW,
If you want line wrapping so that the text beyond the end of a line wraps to the beginning of the next line, you should check out my hd44780 library:
With the hd44780 library you can enable linewrapping by calling lineWrap().
--- bill