Project Level Defines

If it doesn’t already exist or is in the pipeline I would very much like to see project level defines.

Right now I am working on a project with numerous files and it is a bit of a pain to have to edit each one to turn enable, say, “debug” code.

Being able to define items at the project level would mean setting my “debug” define in one place (the project) and have it testable in all files of the project, hopefully library files as well.

Thanks.

You may be interested in the Python program that I have written to manage the compiling and uploading of my Arduino programs. I don't use the Arduino IDE, but the Python program calls it to do the hard work.

The idea behind the Python program is that it takes the files required to compile a program and copies them into a temporary directory structure of the style required by the Arduino system. This means I can choose my own locations for the files while I am editing them. For example I don't need to have the file myProgram.ino in a directory called myProgram.

I suspect it would not be too difficult to adapt the Python program to accommodate the sort of thing you want.

...R

There have been multiple attempts to get this feature added in various forms but all have been rejected, for example: https://github.com/arduino/arduino-builder/pull/29. The logic seems to be that not allowing this forces the library developers to create more beginner friendly APIs but sometimes you just need the preprocessor so I think this would be a very useful feature. Interestingly the .org folks have recently added this feature to their IDE https://github.com/arduino-org/Arduino/pull/16.

The only solution I've found is to do the define in the sketch before the include and then move all code that depends on that define to the .h file. An example of this used for switching debug output is https://github.com/Palatis/arduino-softpwm. Another somewhat related technique is that you can set defines with a custom tools menu but this is board dependent so probably not useful to your application. An example of this is: https://github.com/SpenceKonde/ATTinyCore/pull/45