1

I've a little problem, I'm trying to create a library with processor variables for tune it.

So in .ino I declared my preprocessor var, but preprocessor variables appear not defined in my library. (Notice that I've create a folder test/test.h in libraries directory of Arduino IDE)

Some code to reproduce the problem :

test.ino :

#define TEST
#include "test.h"
void setup() {}
void loop() {}

test.h (edited, reverse error message, this is solution)

#if defined(TEST)
 #error "DEFINED"
#else
 #error "NOT DEFINED"
#endif

If I compile it, I fall on #error "NOT DEFINED".

Somebody with an idea ?

Have a good day

asked Aug 4, 2017 at 8:33
3
  • What you are doing should work IMO, have you tried #define TEST (1) ? Commented Aug 4, 2017 at 9:09
  • Note that using #defines in your sketch will have no effect at all on any usage of those defines in source code (.c and .cpp files), or the header file included in said source code files, in your library. It will only affect the single instance of the header file that is included in your sketch. Using #define in your sketch to configure a library is seldom does what you actually intend it to when you set out. Commented Aug 4, 2017 at 11:06
  • You should understand the concept of the Translation Unit to get a better insight into why #define in the sketch won't affect your library's source code operation. Commented Aug 4, 2017 at 11:13

2 Answers 2

0

The code is working properly. You have mixed up your error messages. The code should be:

#if defined(TEST)
 #error "DEFINED"
#else
 #error "NOT DEFINED"
#endif

UPDATE: The question was edited after the time of this answer to correct the mixed up error messages.

answered Aug 4, 2017 at 8:45
0
0

Please, start by reading the Writing a Library for Arduino Tutorial. That will solve your question.

answered Aug 4, 2017 at 8:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.