Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Library writers >> A "Hello World" Library
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1144744422

Message started by zambetti on 04/11/06 at 08:33:42

Title: A "Hello World" Library
Post by zambetti on 04/11/06 at 08:33:42
Since we are still writing the documentation for how to build a library, anyone wanting to develop them right away might find this sample library useful.

http://people.interaction-ivrea.it/n.zambetti/wiring/Test.tar.gz

It is a "hello world" style library that demonstrates:

Use of core Wiring API functions in your library.
Use of other libraries in your library.
Inclusion of examples with your library.
Specification of syntax colors.
Instance properties (variables).
Private and public methods (functions).

Title: A "Hello World" C Library
Post by zambetti on 04/28/06 at 14:56:52
The latest 0006 release (you may have to re-download) enables support for libraries written in C (normal libraries are written in C++). I think this sample library will be very helpful for getting an understanding of how to implement libraries in C.

http://people.interaction-ivrea.it/n.zambetti/wiring/TestC.tar.gz

It is a "hello world" style library that demonstrates:

Use of core Wiring API functions in your C library.
Hacks for having "public" and "private" functions in C libraries.
Inclusion of examples with your C library.
Use of definitions/constants in your C library.
Specification of syntax colors.

Also, some handy code for fading LEDs and converting strings to integers : )

Note: Wrapping C code with a C++ class is also easy with the library system. It is very handy for making geeky C libraries friendly. It is done with a subfolder called "utility" in your library's folder. If you peek into the code for the "Serial" or "Wire" libraries, you can see how this is done. A simplified example of this will be provided with the documentation.

Title: Re: A "Hello World" C Library
Post by Alan_Kilian on 09/15/06 at 18:17:04
I just figured out the little bit of magic I needed to write my own library.  :D

I couldn't figure out how to build the library since there's no Makefiles anywhere.
(Yeah, I'm an old-school guy. I've been at this for 25 years.)

So I decided to just try something. I copied libraries/Servo/* to libraries/Alan/ and then
changed all the occurrences of "Servo" into "Alan" in the source and in file names.

Then I added some code to an existing .pde

Alan myalan;

setup() {
myalan.attach(0);
}

And IT WORKED!!!  :o

So now it's on to trying to write a library to support my Gyration gyro instead of
having it all pasted in my main code. (I want to use an interrupt routine to schedule
the I/O to sample the gyro rate, so a library seems like the right idea.)

Title: Re: A "Hello World" Library
Post by zambetti on 09/24/06 at 18:59:04
"I couldn't figure out how to build the library since there's no Makefiles anywhere."

It automagically compiles whenever you start wiring, verify a sketch, or upload to the Wiring board. The compilation also links against the Wiring source and all other compiled libraries, so you shouldn't have to worry about inter-library dependencies much at all.

Your gyro library sounds like a great idea! Definitely keep us updated with your progress/questions.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.