Go Down

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

gaelperr

Hello,

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 ;)

Robin2

Perhaps Google arduino create library

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

pert

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:
https://github.com/wizard97/ArduinoRingBuffer
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" {
#endif

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

That's really all there is to it.

Go Up