Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpLibrary writers › A "Hello World" Library

Page Index Toggle Pages: 1
A "Hello World" Library (Read 7998 times)
04/11/06 at 08:33:42

zambetti   Offline
YaBB Newbies

Posts: 21
*
 
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).
 
IP Logged
 
Reply #1 - 04/28/06 at 14:56:52

zambetti   Offline
YaBB Newbies

Posts: 21
*
 
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.
 
IP Logged
 
Reply #2 - 09/15/06 at 18:17:04

Alan_Kilian   Offline
Full Member
Wiring? It looks like
Java to me.

Posts: 118
***
 
I just figured out the little bit of magic I needed to write my own library.  Cheesy

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!!!  Shocked

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.)
 
IP Logged
 
Reply #3 - 09/24/06 at 18:59:04

zambetti   Offline
YaBB Newbies

Posts: 21
*
 
"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.
 
IP Logged
 
Page Index Toggle Pages: 1