Go Down

Topic: lcd.print and lcd.write at one line (Read 2305 times) previous topic - next topic

Axinar

hi,
i what to write on an lcd in one line caracters that i create and normal latin letters.
if i want to write ??????????? that means temperature in Greek i have to create the first and the 9th letter with cd.createChar(1, Thita);
and then i must write this code:

   lcd.home();          //Grafoume THERMOKRASIA
 int n=0;
 lcd.write(n);
 lcd.setCursor(1,0);
 lcd.print("EPMOKPA");
 lcd.setCursor(8,0);
 lcd.write(1);
 lcd.setCursor(9,0);
 lcd.print("IA:");

it is possible to write it in one line?
also it cant compile lcd.write(0);
and i use the  int n=0;
 lcd.write(n);

thanks!
those who can,do.
those who can't, teach.
those who can't teach, admin.

robtillaart


YOu can write it in less lines

Code: [Select]

  lcd.home();          //Grafoume THERMOKRASIA
  // lcd.setCursor(0,0);
  lcd.print("TEPMOKPASIA:");  // just write the whole word with placeholders (preferably some that make sense)
  lcd.setCursor(0,0);
  lcd.write(0);  // write ?
  lcd.setCursor(8,0);
  lcd.write(1);  // write ?

33% less lines ;)  and easily testable without the greek chars
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

bperrybap

#2
Jan 06, 2013, 09:16 am Last Edit: Jan 06, 2013, 09:21 am by bperrybap Reason: 1
This is a situation where octal constants come in handy.
Code: [Select]
\nnn
Is an octal character value that can be used inside literal strings.
The nnn is an octal value between 0 and 377
However, 0 or null is special in literal strings since it marks the end of string so you can't use zero
inside a string.
But other values are ok inside a string.
If you switch your custom characters to use 1 and 2 instead of 0 and 1
then you can use a single literal string.
In your case this would be:
Code: [Select]
lcd.print("\001TEPMOKPASIA\002:");

This will insert 1 at the front and 2 near the end of the string so you
can do it all at once. You can even use the F() macro to avoid using RAM for the sting:
Code: [Select]
lcd.print(F("\001TEPMOKPASIA\002:"));

--- bill



robtillaart

good thinking Bill, that is even simpler!
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Axinar

bperrybap, thanks for your good idea.
the only problem that i have know is that i need al the 8 custom caracters!
i try many thinks to solve it.
something like n=0 or n=000 or n=0 and \nnn on text, but nothing! the result is that appears the character that i have in possition 2!
those who can,do.
those who can't, teach.
those who can't teach, admin.

floresta

The addresses for the eight custom characters have redundant addresses due to 'foldback memory addressing'.  

Addresses 0x00 <--> 0x07 (0 <--> 7) are the primary addresses and addresses 0x08 <--> 0x1F (8 <--> 15) are the foldback (redundant) addresses for the same eight characters.  

Perhaps you can use this feature to solve your problem if the Arduino compiler will permit it.


Don

Axinar

Sorry floresta,
it doesnt work! i can complile it but is not showing anything.
those who can,do.
those who can't, teach.
those who can't teach, admin.

floresta

#7
Jan 06, 2013, 08:37 pm Last Edit: Jan 06, 2013, 08:44 pm by floresta Reason: 1
Quote
Sorry floresta,
it doesnt work! i can complile it but is not showing anything.


Have you been successful displaying any of your custom characters by any means?  If you have then why don't you try the same code with the foldback addresses and see what happens.  This will tell us if the technique is valid or not.

By the way there are at least four Greek characters in the standard HD74480U controller if it has the common A00 ROM.  Theta is 0xF2 and Sigma is 0xF6.  I looked at some other data sheets and most of them had the same characters at the same locations.

Don

bperrybap

Again, you cannot use the zero character inside a C string.
C uses the 0 to signify the end of the string.
There is nothing you can do to change that.
This not something that can be worked around.
That is why I said not to use zero. It simply cannot be used inside a C string.

Don's suggestion was a good one.
And that was that is that characters 8 to 15 are the same as 0 to 7
This means you can use 8 instead of 0
Because of that you can simple use 8 inside a C string instead of 0
to access the zero custom character.


Sorry floresta,
it doesnt work! i can complile it but is not showing anything.


This should work. Show your code.

keep in mind that 0x8 is \010 in octal
so to use the zero custom character you would use \010

And if your character set supports it, Don's other suggestion will at least get you
theta and sigma which will save you two custom characters.
Just convert the hex values to octal
theta  is 0xf2 or \362
sigma is 0xf6 or \366

--- bill

Axinar

My programming skills are in junior level.
i didnt unterstund that \010 has the same result that \000 must have!
my code now is lcd.print("\010EPMOKPA\001IA:"); and it is working perfectly!
thanks guys!
those who can,do.
those who can't, teach.
those who can't teach, admin.

bperrybap


My programming skills are in junior level.
i didnt unterstund that \010 has the same result that \000 must have!
my code now is lcd.print("\010EPMOKPA\001IA:"); and it is working perfectly!
thanks guys!


Just to be clear here.
From a programming point of view \000 and \010 are different.
\000 is zero and \010 is eight.

The reason it works is due to what Don pointed out.
The lcd treats characters 8 through 15 the same as characters 0 through 7.
So while the code is now sending 8 to the LCD instead of 0,
the LCD interprets 8 as 0 and so it works.

And to keep things even simpler did you try Don's other suggestion?
Using the built in values for theta and sigma?
It works on my lcd.
For theta I can use 0xf2 or \362
for Sigma I can use 0xf6 or \366

Using these you would save having to define and use custom characters
for the theta and sigma.

--- bill

bperrybap

Since you seem to doing something related to temperature, another useful
character when using temperature is the degree symbol.
This is often character 0xdf or \337
So if you are defining a custom character for the degree symbol, you could
try to see if your character set has the degree symbol built in.

--- bill

Tom Carpenter

#12
Jan 06, 2013, 10:24 pm Last Edit: Jan 06, 2013, 10:27 pm by Tom Carpenter Reason: 1
If you don't want to convert to Octal, you can add letters in hex:
Code: [Select]
char string[] = "\x30\x31\x32";
is equivalent to:
Code: [Select]
char string[] = "123";
is equivalent to (octal):
Code: [Select]
char string[] = "\060\061\062";
~Tom~

bperrybap

I just had a quick look at the ANSI standard for escaped character constants to see
what is in the latest standard.
I came away with a new understanding of the standard requirements
(which I think is different from how it worked years ago) and a
feeling that it is kind of a bummer the way it is defined since
it can create potential unexpected issues based on peoples assumptions
of how it works vs how it really works.
The ANSI standard defines these types of constants as:

Each octal or hexadecimal escape sequence is the longest sequence of characters
that can constitute the escape sequence.


So that can create unexpected issues depending on what follows next.
i.e. trying to print the degree symbol followed by 'C'.
"\xdfC"

Would be a problem since the C is a valid hex character.
the hex constant becomes 0xdfc which is too large and then either generates
an error or a warning. If a warning you get the single value 0xfc instead of degree symbol and 'C'.

Same is true for Octal.
While octal has the same issue, it gets "lucky" more often than hex
since octal only uses the numbers 0 to 7.
"\337C" would work as C is not a valid octal character.

Consider this example:
Suppose custom character 1 was an upside-down exclamation
and you wanted a phrase to start with that:

"\00142 is the answer!"

The constant again becomes too large as the compiler interprets
00142 as the value instead of just 001.


It means that you should always use multiple strings and let the compiler
combine them to avoid any potential issues.
i.e.

"\x30" "C"
"\001" "42 is the answer!"

So the safest way to handle escaped constants embedded in a string with other characters
is to always isolate the escaped constants inside their own quotes.

i.e.
Code: [Select]
lcd.print("\010" "EPMOKPA" "\001" "IA:");

lcd.print("\x08" "EPMOKPA" "\x01" "IA:");

lcd.print("\xf2" "EPMOKPA" "\xf6" "IA:"); // use theta an sigma from LCD character set



--- bill

Go Up