Understanding libraries and header files

Hi Everyone,

I'd like to be able to use a define inside a custom library that is declared either in my main scketch or in another .h file in a multi-file scketch, is there any way of doing this?


is there any way of doing this?

Anything's possible. You need to be a little clearer on what you want to do.

Hi Paul,

Something like this: Main scketch:

define testing

Custom Library:

ifdef testing

//Do something

end if

I've been reading up on preprocessor directives. The scope of a directive appears to be the file in which the directive is defined. So, #define in the sketch will NOT be defined in the library.

If the #define is in a header file that is included in the sketch and the source file, then it has the same meaning in both places. But, of course, it can't be changed in the sketch.

I suspect that you need to find another way of triggering optional behavior.

The downside of this is that the code will need to contain all the optional stuff, even when it will never be used.