Reply to topic  [ 11 posts ]  Go to page Previous  1, 2
Hobby Components 1602 SmartLCD (HCMODU0122) 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 781
Post Re: Hobby Components 1602 SmartLCD (HCMODU0122)
This is one of the common sources of confusion when first learning to program in C++. This is because there are two common methods to handle strings which can at first sight look similar to each other but are in fact different and not directly interchangeable. The first type is a C++ String (note the capital) object. This is the type that you are using in your sketch and it's actually a class (think of it like and Arduino library) that each time you create a string your actually creating an instance (a copy of the library) which has a number of member functions and properties associated with it. These then handle the string for you in the background. However, the print function is expecting a different type of string called character string which is just an array of characters with a null terminating byte at the end of it.

The former makes handling strings easier as its handling manipulation (concatenation, comparison, copying, etc) for you in the background. However the disadvantage is that this method is memory intensive. This is not a problem with programming in C++ on a PC with gigs of memory, but on a tiny microcontroller every byte of RAM is important. This is also why the library, being written for Arduinos with small amounts of memory, only makes use of character arrays which using the bare minimum of memory. The option is then there to add your own conversion function if memory isn't an issue in your sketch.

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Fri Jun 22, 2018 1:08 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD