Go Down

Topic: Writing Libraries (Read 783 times) previous topic - next topic

Retroplayer

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?

Denbo

Did you try the tutorial on the official Arduino website?

http://arduino.cc/en/Hacking/LibraryTutorial

Retroplayer

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.

PaulS

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.

PeterH


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.
I only provide help via the forum - please do not contact me for private consultancy.

Retroplayer

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.

Nick Gammon

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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

WizenedEE


Docedison

#8
Feb 15, 2013, 01:03 pm Last Edit: Feb 15, 2013, 01:08 pm by Docedison Reason: 1
Thinking in C++ and Programming in C++, Nice, Free books.... Code too.
Not for beginners, though.

Bob
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

mjkzz

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 . . . :-)
Search for "mjkzz" on eBay :-)

Go Up