LCD Library Errors

I’m trying to create a library so that I can print to the LCD unit. The original program is so large, I’d like to create a support library to relieve some of the confusion. I used a modified example from the LCD library for the .ino file and created a .cpp file along with a header file. They are attached.
I keep getting this error:
J:\sketches\libraries\LCDlibraryTest\Lcdtest.cpp:17:2: error: ‘lcd’ was not declared in this scope
lcd.print(_mesg);

I don’t understand why lcd in the .cpp file is being interpreted as a variable when it’s part of the LiquidCrystal library. Is this just a quirk of C++ and I can only use the LCD library in the .ino file?

Lcdtest.cpp (297 Bytes)

LCDtest.h (231 Bytes)

LcdLibraryTest.ino (586 Bytes)

LcdTest test("Will this work?");

No.

Are you learning about Classes in this example, or are you already familiar? Are you trying to use inheritance?

you want to #include both your new Class/Library and the LiquidCrystal library.

class LcdTest
{
public:
    LcdTest(String mesg);
    void LcdPrint();
    private:
    String _mesg;
    //int _cur1;    int _cur2;
};

don't forget the constructor:

LcdTest::LcdTest(){};

and a few other things....

Most people don't find that the LiquidCrystal library needs a wrapper...

Most people don't find that the LiquidCrystal library needs a wrapper...

And it certainly doesn't need for you to wrap the data that it is to display in a String that it has to unwrap.

BulldogLowell: LcdTest test("Will this work?");

No.

Are you learning about Classes in this example, or are you already familiar? Are you trying to use inheritance?

you want to #include both your new Class/Library and the LiquidCrystal library.

class LcdTest
{
public:
 LcdTest(String mesg);
 void LcdPrint();
 private:
 String _mesg;
 //int _cur1; int _cur2;
};

don't forget the constructor:

LcdTest::LcdTest(){};

and a few other things....

Most people don't find that the LiquidCrystal library needs a wrapper...

I am semi familiar with classes, yet know I have a lot to learn. My actual program is getting quite large and wanted to see if I could shrink it down a bit by creating a library that supports a lot of the recurring functions. This is a test sketch which if I can get it to work, I'll insert it into the actual. I do have the construct in the source (.cpp) file and you've basicly quoted what I already have. What does it mean when you say [/code]? Am I that bad of a newb? I'm way below you folks knowledge and experience, but catch on rapidly. I have a lot of experience in VBA, VB and some java, C++ and C#.

Gadgetman9: I have a lot of experience in VBA, VB and some java, C++ and C#.

Great news. The Arduino is programmed entirely in C++. So if you know C++, you know this.

Delta_G: Great news. The Arduino is programmed entirely in C++. So if you know C++, you know this.

I have limited experience in C++. I can not figure out why C++ is treating lcd.print as if lcd is a variable not declared in scope. That is why I asked this question.

might be a good idea to post your code that's growing to large to see if theres a better way to deal with the lcd.

Gadgetman9: I have limited experience in C++. I can not figure out why C++ is treating lcd.print as if lcd is a variable not declared in scope. That is why I asked this question.

Because lcd isn't a part of the library, it is an instance of the LiquidCrystal class and it is only declared inside the .ino file. It doesn't exist inside the .cpp.

Adding an extern declaration to your library would tell it that somewhere else in another compilation unit exists this object called lcd that it can use.

extern LiquidCrystal lcd

Alternatively if you don't always know that the LiquidCrystal instance will be named lcd, you could pass whatever instance as a parameter to the constructor of the LcdTest class.

Thank you Delta_G. That solved the problem. I’m very grateful for your solution