Is there an internal variable that holds the sketch name?

Is there anyway of putting a pre-compiler switch into a library to make it behave differently depending on which project it's in?

Here's the background.... I have a number of libraries that use a lot of progmem to store messages and error warning that get echoed to the serial port as the project runs. These messages are very useful (especially during debugging and development) but not essential for normal running.

If the library is being used on a mega, then I normally have plenty of memory for the progmem stuff, but when the same library is being using in a different project on a smaller processor (mini-pro) then I can't afford any non-essential memory.

Can I use some pre-compiler directive to switch my error messages (i.e. the stuff in progmem) on or off depending on the name of the top level sketch?

You can the name of the file from FILE

The FILE is available but what you can als do is define yourr own debuf flag. Put all the debug crap between

#ifdef DEBUG_MYPROJECT
//do debug stuff here
Serial.print(F("I'm in debug!"));
#end

You should use a better (but unique!!) name then DEBUG_MYPROJECT.

And when you use

#define DEBUG_MYPROJECT

The debug messages are compiled and when you remove that or comment it out it does not.

You can even use multiple defines for different parts of code debug. For example when you work on part A you might not need the debug of part B so you can disable that to save memory.

And when debugging, make the messages direct.

//Don't let it print mega long things like
Serial.println(F("Error: The value is not in the range of 1 to 4 like t should be."));
//but
Serial.println(F("E Out of range"));