Go Down

Topic: Create Function library (Read 214 times) previous topic - next topic



I have read it's possible to create a library for function (not for method with C++)
Like the function : DigitalWrite for example. this function is create on "wiring_digital.c"
How can I create my library for function ? I have to create an .c and a .h file ?
On Google I have found only explication for library with method on C++ with object etc..

Finally I want to call the function in my main program, for simplify the programmation

Thank you for your help ;)


Perhaps Google arduino create library

Two or three hours spent thinking and reading documentation solves most programming problems.


The only tricky thing is that Arduino sketches are C++, not C. So to use C code from C++ you need to wrap it in extern "C" {}

Here's the first example I found of a C library for Arduino:
It's not the best minimal example.

Note how in the .h file they add this before the start of the C declarations:
Code: [Select]
#ifdef __cplusplus
extern "C" {

and this after:
Code: [Select]
#ifdef __cplusplus

That's really all there is to it.

Go Up