Writing Libraries

Are there any good tutorials on writing proper libraries? I am moderately new to C and very new to C++. I have found that I really like the OO stuff in C++ and just trying to figure out where to start with regards especially to writing libraries (classes, class hiearchy, etc...)

I know there is C++ stuff out there, but anything specific for arduino for dummies?

Did you try the tutorial on the official Arduino website?

Yes. No problems with any of the subjects that covers. I guess I am hoping to find something a bit more advanced. All books, etc... always seem to be aimed at beginners and always seem to stop right where I already am at.

A library is nothing more than a header file that defines a class and a source file that implements the class. There is nothing particularly advanced about that. I'm having a hard time envisioning what your problems might be.

PaulS:
A library is nothing more than a header file that defines a class and a source file that implements the class.

The part in bold assumes the library contains a class - it doesn't have to.

It's not so much a 'problem' as just being a complete newbie to C++, but not C. I get the standard class structure. No problem there. I can write libraries, I can build a simple class structure. Just looking for more advanced tutorials to learn more about using more features of C++ with Arduino. I have been reading books about C++, so I am learning. But so far nothing specific and with examples for the arduino. You were mentioning some more advanced technics to me in another thread about class hierachy, etc... and all those concepts were foreign to me. I'd like to learn how to use them.

Oh well, perhaps something like that doesn't exist. Just thought I would ask if anyone knew of any.

Sounds to me like you are trying to find a problem to fit the solution.

I will write a library simply to save repeating the same code in multiple projects. Not necessarily even using a class. If a class is warranted, I'd use it. Or a namespace. Or a struct.

The Arduino compiler is basically straight C++, so there is no real need to look for Arduino-type solutions.

Take HardwareSerial, for example. Since the chips can have multiple serial ports, they made the port interface a class, and each individual port an instance of the class.

Just find a book on C++.

I like Thinking In C++ by Bruce Eckel

Thinking in C++ and Programming in C++, Nice, Free books.... Code too.
Not for beginners, though.

Bob

I just wrote one, it was surprisingly easy and it compiles on the fly -- change .cpp source, you run your sketch, it is compiled!!!

I wonder why I was not into Arduino world before . . . :slight_smile: