I have written simple code to enable toggling of
serial.print debug data.
#define DEBUG #ifdef DEBUG #define DEBUG3(x,y,z) Serial.print(x);Serial.print(" ");Serial.print(y); Serial.print(" "); Serial.println (z) #define DEBUG2(y,z) Serial.print(y);Serial.print(" ");Serial.println (z) #define DEBUG(z) Serial.println(z) #define DEBUGln Serial.println(""); #else #define DEBUG3(x,y,z) #define DEBUG2(x,y) #define DEBUG(x) #define DEBUGln #endif
Then I can just call
DEBUG3("words",value,"words"); anywhere in the sketch and it will automatically print out the text, int, strings, etc with a single space between and automatically go to next line etc etc.
Just define the correct number of fields to print and separate using commas.
If I want to turn off debug then I just comment out
#define DEBUG at the top.
Now the issue is I don't want to copy in this code every time I want to use it, so it makes sense to make it a library so that I can just call something like:
#include <SERIAL_DEBUG.h> #define DEBUG (or //#define DEBUG) //to enable or disable
The reason being that sometimes I might want to print up to 10 things on a single line (not very often but it could happen).
This is my first library attempt and I'm having a hard time finding any information on how I would go about setting up the .h and .cpp files for this type of
#define DEBUG(x) Serial.println(x) and the
#define DEBUG (from sketch) parts.