Tutorial with Serial on/off for debug. / Sending error message to error handler

Hello All

Not too long ago I found a tutorial that included a way to turn serial on/off for debugging and it included also a way to send messages to an error handler that also turn a led on or off.

I dont know anymore what the main topic of the tutorial was and I unfortunately dont remember more details about the tutorial.

Unfortunately I lost the page and cannot find it anymore. Does anyone recognize the page or has any one seen a similar page or has ideas how to acomplish this?

Thank you!

moses

You can do it easily by wrapping all of your print statement in pre-processor conditionals. It's basically a fancy way of dynamically telling the compiler what to compile (and what not to compile) when uploading your code to your board.

Here is an example:

This will print "debugging..." 10 times a second:

#define DEBUG

void setup() 
{
#ifdef DEBUG
  Serial.begin(115200);
#endif
}

void loop()
{
#ifdef DEBUG
  Serial.println("debugging...");
#endif

  delay(100);
}

This is the same sketch, except line 1 is commented out. It still compiles, but does not print anything out:

//#define DEBUG

void setup() 
{
#ifdef DEBUG
  Serial.begin(115200);
#endif
}

void loop()
{
#ifdef DEBUG
  Serial.println("debugging...");
#endif

  delay(100);
}