How to use #define in a library I'm trying to write? 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 &lt;SERIAL_DEBUG.h&gt;
#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.
Not a direct answer to your question, but I would suggest a different
approach based on streaming output, as described in the Arduino
Playground: Adding Streaming (insertion-style) Output. In
a nutshell, you define the &lt;&lt; operator for Serial (and any other
object that inherits from Print) in a way that allows you to write
things like:

Serial &lt;&lt; "My name is " &lt;&lt; name &lt;&lt; " and I am " &lt;&lt; age &lt;&lt; " years old.";


Now you can define a Debug object which would be, depending on whether
you want debugging output or not:


an alias to Serial
a dummy object that just discards its input.


Example:

#define DEBUG_ON

// From https://playground.arduino.cc/Main/StreamingOutput
template&lt;class T&gt; inline Print&amp; operator&lt;&lt;(Print &amp;obj, T arg)
{ obj.print(arg); return obj; }

#ifdef DEBUG_ON
# define Debug Serial
#else
class DummyStream {
public:
    template&lt;class T&gt; DummyStream&amp; operator&lt;&lt;(T arg)
    { (void) arg; return *this; }
} Debug;
#endif

void setup()
{
    const unsigned long BAUDRATE = 9600;
    Serial.begin(BAUDRATE);
    Debug &lt;&lt; "Serial port open at " &lt;&lt; BAUDRATE &lt;&lt; " bps\r\n";
}