Go Down

Topic: custom character in a string (Read 996 times) previous topic - next topic

terzyans

Hi everybody,
I would like to create a string that contains usual characters with custom ones. For example I would like to print a string
"High my friends. I am " a smiley character " today".
I can create the smiley character , but do not know how to include it into a string. I searched the internet and there was one reply to use \xhh where hh is hex value of the character. How I can find the hex value of a custom made character. Each of ASCII characters have a Hex value, but what is it for a custom made character?
Thanks a lot, Simon

Nick Gammon

Quote
I can create the smiley character


What do you mean? For what device?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

TanHadron

If you're looking for the old "white smiley" and "black smiley" from the original IBM PC font, the white smiley is a 0x01 and the black smiley is an 0x02.  They're NOT standard ascii characters.  So like Nick asked, it depends a lot on your device.

I recommend you send every character from 0x01 to 0xFF and see what they look like.  Then pick the one that looks the most like what you want.

I'm not entirely sure the \xhh system works in Arduino C.  However, I'm certain you can just slam the binary data into the string, as long as it's not a 0.

Nick Gammon


I'm not entirely sure the \xhh system works in Arduino C.  However, I'm certain you can just slam the binary data into the string, as long as it's not a 0.


It's normal C++. It has the same rules.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

majenko

I assume you mean for an LCD display.

When you create a custom character on an LCD it occupies one of the first 8 (I think) characters of the ASCII character set.

So, you can embed those 8 ASCII codes using the \xNN format:

Code: [Select]

lcd.print("Today I am a \x01");

AmbiLobe

ASCII is a subset of Unicode which uses code points. Many unusual characters are available.

Here is the chart of 2 byte Unicode for ASCII
http://www.unicode.org/charts/PDF/U0000.pdf

see page 61 of the following document to study UTF-8 and the other coding specs. For example,

The 12000 hex code point is converted to UTF-8 bytes F0 92 80 80. That calculation is explained in this linked document on page 94 , Table 3-6 :http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf 

see my website on Cuneiform characters handled in Unicode :
http://cuneiformclub.blogspot.com/
Here is an excerpt from my website on Cuneiform Unicode :
UTF-8 encoding is a good choice for viewing Cuneiform fonts. It is not clear when UTF-8 is not a good choice. This Cuneiform Club has the decimal code points near 73728 that are interpretted correctly. This is when the "encoding" menu specified UTF-8. This page will explore this question of why UTF-8 is better than UTF-32. The decimal 73728 is more than hex 00FFFF and less than hex 10FFFF, so 8 bits and 16 bits are not enough. UTF-16 uses two 16 bit numbers to represent numbers over hexadecimal FFFF. UTF-32 uses one 32 bit number less than hex 10FFFF.

Here is my website with Perl programs for Unicode
http://greekalphabet.blogspot.com/


code points for Cuneiform
http://www.unicode.org/charts/PDF/U12000.pdf
I am going to get going.

terzyans

Hi
Thanks to everybody who responded.
It is kind of a theoretical or programing question.
I am sorry to not mention that the character was created for LCD display.
Instead of making three comands
lcd.print ("My friends I am ");
lcd.write (byte(1));
lcd.print (" today.");
I  was planing to create a string With all three parts and then
lcd.print(string[]);

Is the answer of majenko correct?, Yesterday I created a character with number 0, and tried
following:
char mystring[]=("bar " \x00);
lcd.print (mystring[]);
it printed only the word bar.
    Simon

Nick Gammon

Quote
char mystring[]=("bar " \x00);


I don't follow that. Use code tags please.

Read this before posting a programming question
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

Quote

Instead of making three comands
Code: [Select]
lcd.print ("My friends I am ");
lcd.write (byte(1));
lcd.print (" today.");
I  was planing to create a string With all three parts ...



Code: [Select]
lcd.print ("My friends I am \x01 today.");
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

UKHeliBob

This page http://arduino.cc/en/Reference/LiquidCrystalCreateChar shows how to create and print a custom smiley character to an LCD.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

majenko


Hi
Thanks to everybody who responded.
It is kind of a theoretical or programing question.
I am sorry to not mention that the character was created for LCD display.
Instead of making three comands
lcd.print ("My friends I am ");
lcd.write (byte(1));
lcd.print (" today.");
I  was planing to create a string With all three parts and then
lcd.print(string[]);

Is the answer of majenko correct?, Yesterday I created a character with number 0, and tried
following:
char mystring[]=("bar " \x00);
lcd.print (mystring[]);
it printed only the word bar.
    Simon


Character 0 ("\x00" or just "\0") is a special character that denotes the end of a string.  If you want to print character 0 you will have to do it explicitly with an lcd.print((char)0); as you cannot embed character 0 in the middle of the string - that embedded character 0 immediately becomes the end of the string.

terzyans

Thanks to everybody again.
Nick's answer is complete.
I am sorry for the sad face in my previous post. I do not know how it got there. I was planing to type
char mystring[]=("bar"  \x00  );
Simon

Nick Gammon

You still have the sad face. Use code tags! (how many times?)

Read this before posting a programming question
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

terzyans

It seems the editor puts that face instead of = ( . Before posting I checked it on preview and everything was OK
Simon

Nick Gammon

It does, if you don't use code tags. <sigh>
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up