Pages: [1] 2   Go Down
Author Topic: custom character in a string  (Read 786 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18810
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I can create the smiley character

What do you mean? For what device?
Logged


Offline Offline
God Member
*****
Karma: 25
Posts: 526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18810
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
lcd.print("Today I am a \x01");
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

New England
Offline Offline
Sr. Member
****
Karma: 7
Posts: 295
Natural Semiinductor
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

I am going to get going.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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[]smiley-cry"bar " \x00);
lcd.print (mystring[]);
it printed only the word bar.
    Simon
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18810
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
char mystring[]smiley-cry"bar " \x00);

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

Read this before posting a programming question
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18810
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Instead of making three comands
Code:
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:
lcd.print ("My friends I am \x01 today.");
Logged


East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4264
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This page http://arduino.cc/en/Reference/LiquidCrystalCreateChar shows how to create and print a custom smiley character to an LCD.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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[]smiley-cry"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.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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[]smiley-cry"bar"  \x00  );
 Simon
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18810
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Read this before posting a programming question
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18810
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It does, if you don't use code tags. <sigh>
Logged


Pages: [1] 2   Go Up
Jump to: