Hi all, I notice in the lcd library there is no function to print a variable. I have tried this;
lcd.println(n);
lcd.print("c");
I gave n the value 18 before set up. On the lcd display I get the 18 but after that there is what looks like 4 'U's laid on their side. After that is the 'c' and then the cursor. I need to be able to print out a variable on the lcd with a 'c' for centigrade on the screen. How can I do this without the 'U's? Thanks.
Hello
Don't use println
What type is variable n ? If it's a char array, make sure it is null-terminated
use print.
if it doesn't work for you - show a complete compileable sketch in code tags.
Thanks guix. That has fixed it. In ordinary programming, not in the lcd library, to print a variable number you have to use println(n). So I have used print(n) for a variable where n is an int and a number. Because 'c' is a character I use print("c"). If I wanted a decimal number I wouldn't use 'int'. So now I can easily vary 'n' in the display. Now showing on display as '18c_' where the stroke is the cursor. '18' was set earlier as intn=18. Can later in the program change the value of 'n' to any other int number.
yes should be lcd.print(n).
it's seems you still have a misunderstanding about print and println.
Both functions take the same parameters. Meaning you can use them to print constant text or variables and modifiers the same way. The only difference is that println adds a CR LF at the end. If you check the implementation of print and println (you find them as par of the Print.h and Print.cpp) you will see that even if you call println it will first call print and afterwards adds the CR LF.
No you don't have to use println.
You only use println if you want a newline after the value you printed