Pages: [1]   Go Down
Author Topic: Trying To Create A Library With Poor Understanding Of C++... This Will Go Well  (Read 905 times)
0 Members and 1 Guest are viewing this topic.
Leicester
Offline Offline
Newbie
*
Karma: 0
Posts: 3
What does 'personal text' even mean?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to develop a library to display scrolling text on a single seven segment display

I wrote all the functions in standard C and tested them in a single file. They all worked.

Now I am trying to convert them to C++ to create the library, everything is going horribly wrong.

I have read http://www.arduino.cc/en/Hacking/LibraryTutorial and followed it as closely as possible.

One of the major things that has been confusing me is the lack of a byte type in C++ which I had thought was required to shift out bytes to the display. I have tried substituting char. This seems to not work at all. Any advice on this?

All my code is at http://www.ratbum.com/arduino/ScrollText.html and is also attached.
I will post it in code tags if people prefer this.

The error messages that I am getting are below. I seem to be having massive problems with declaration of constants.
Code:
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp: In constructor 'ScrollText::ScrollText(int, int, int)':
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::disp0' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::disp1' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::disp2' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::disp3' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::disp4' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::disp5' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::disp6' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::disp7' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::disp8' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::disp9' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispA' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispB' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispC' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispD' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispE' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispF' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispG' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispH' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispI' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispJ' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispK' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispL' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispM' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispN' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispO' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispP' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispQ' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispR' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispS' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispT' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispU' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispV' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispW' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispX' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispY' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispZ' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::disp_' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::dispBlank1' with 'const' type 'const char'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::blank' with 'const' type 'const int'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:55: error: uninitialized member 'ScrollText::betweenLetters' with 'const' type 'const int'
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp: In member function 'void ScrollText::scrollText(char*)':
/Users/Thomas/Documents/Arduino/libraries/ScrollText/ScrollText.cpp:81: error: request for member 'length' in 'text', which is of non-class type 'char*'

* ScrollText.zip (2.98 KB - downloaded 2 times.)
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try the attached version smiley

* ScrollText.zip (2.14 KB - downloaded 9 times.)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
One of the major things that has been confusing me is the lack of a byte type in C++ which I had thought was required to shift out bytes to the display.
Perhaps generic C++ does not have a byte type, but C++ on the Arduino does.

The valuation of the member disp0 is not happening. There are global variables created the same name, and valued. Global variables and member variables with the same name are not a good idea.

Setting pinMode in the constructor of your class is not a good idea. Do you know whether the constructor is called before or after the pin is initialized? Is the pin ready to be initialized when your constructor is called?

You should add a begin() method, similar to Serial.begin(), where that kind of stuff is done.
Logged

Leicester
Offline Offline
Newbie
*
Karma: 0
Posts: 3
What does 'personal text' even mean?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, that solves that problem then, I have changed all my declarations.

Quote
The valuation of the member disp0 is not happening. There are global variables created the same name, and valued. Global variables and member variables with the same name are not a good idea.

I am sorry, I do not understand this. I wish them all to be accessible to all of ScrollText.cpp and nothing else. I don't suppose you could tell me how I go about doing this? Do I have do delete them from ScrollText.h?

Quote
Setting pinMode in the constructor of your class is not a good idea. Do you know whether the constructor is called before or after the pin is initialized? Is the pin ready to be initialized when your constructor is called?
Someone needs to change that tutorial then.
I have created a begin method now; it does sound like a better idea now that you mention it.

Thank you hugely for the help.

The revised code is attached.

* ScrollText.zip (2.99 KB - downloaded 4 times.)
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you take a look at my attached version?

It compiles.
You can take a look at the source if you want to see the syntax for private class constants.

[EDIT] As far as I know, the pinMode does not rely on any previous initialization.
« Last Edit: February 09, 2011, 02:15:41 pm by AlphaBeta » Logged

Leicester
Offline Offline
Newbie
*
Karma: 0
Posts: 3
What does 'personal text' even mean?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you both very much, this is marvellous, and very helpful. I now understand C++ quite a bit better.
Logged

Pages: [1]   Go Up
Jump to: