user37274: 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.

user7508: 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 << operator for Serial (and any other
object that inherits from Print) in a way that allows you to write
things like:
Serial << "My name is " << name << " and I am " << age << " 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<class T> inline Print& operator<<(Print &obj, T arg)
{ obj.print(arg); return obj; }

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

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


user4143: Anything in a header file that is included with #include is literally pasted into the file at the point of the #include.
So anything in your sketch you want to place into a header file you can just place it in a header file and include that file at the same location where the original code was.
So you can have a header file debug.h:
  #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

And include that in your sketch at the right location:
#define DEBUG
#include "debug.h"

Note that the #define DEBUG must come before the #include. Remember: the #include is replaced by the content of the included file, so after preprocessing you end up with exactly what you had before in your sketch:
  #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

The file can be in the same location as the sketch (in which case you should use #include "debug.h" or in a library folder (Arduino/libraries/debug/debug.h) in which case you should include it with #include <debug.h>. In the Arduino IDE it actually makes little or no difference which type of #include you use, but it does serve as a visual reminder that this is either a header included with the sketch ("") or an external library or system header (<>).

37274: <p>I have written simple code to enable toggling of <code>serial.print</code> debug data.</p>

<pre><code>  #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
</code></pre>

<p>Then I can just call <code>DEBUG3("words",value,"words");</code> 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.</p>

<p>Just define the correct number of fields to print and separate using commas.</p>

<p>If I want to turn off debug then I just comment out <code>#define DEBUG</code> at the top.</p>

<p>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:</p>

<pre><code>#include &lt;SERIAL_DEBUG.h&gt;
#define DEBUG     (or //#define DEBUG) //to enable or disable
</code></pre>

<p>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).</p>

<p>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 <code>#define DEBUG(x) Serial.println(x)</code> and the <code>#define DEBUG (from sketch)</code> parts.</p>
 7508: <p>Not a direct answer to your question, but I would suggest a different
approach based on streaming output, as described in the Arduino
Playground: <a href="https://playground.arduino.cc/Main/StreamingOutput" rel="nofollow noreferrer">Adding Streaming (insertion-style) Output</a>. In
a nutshell, you define the <code>&lt;&lt;</code> operator for <code>Serial</code> (and any other
object that inherits from <code>Print</code>) in a way that allows you to write
things like:</p>

<pre><code>Serial &lt;&lt; "My name is " &lt;&lt; name &lt;&lt; " and I am " &lt;&lt; age &lt;&lt; " years old.";
</code></pre>

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

<ul>
<li>an alias to Serial</li>
<li>a dummy object that just discards its input.</li>
</ul>

<p>Example:</p>

<pre><code>#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";
}
</code></pre>
 4143: <p>Anything in a header file that is included with <code>#include</code> is literally pasted into the file at the point of the <code>#include</code>.</p>

<p>So anything in your sketch you want to place into a header file you can just place it in a header file and include that file <em>at the same location where the original code was</em>.</p>

<p>So you can have a header file <code>debug.h</code>:</p>

<pre><code>  #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
</code></pre>

<p>And include that in your sketch at the right location:</p>

<pre><code>#define DEBUG
#include "debug.h"
</code></pre>

<p>Note that the <code>#define DEBUG</code> <em>must</em> come before the <code>#include</code>. Remember: the <code>#include</code> is replaced by the content of the included file, so after preprocessing you end up with exactly what you had before in your sketch:</p>

<pre><code>  #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
</code></pre>

<p>The file can be in the same location as the sketch (in which case you should use <code>#include "debug.h"</code> or in a library folder (<code>Arduino/libraries/debug/debug.h</code>) in which case you should include it with <code>#include &lt;debug.h&gt;</code>. In the Arduino IDE it actually makes little or no difference which type of <code>#include</code> you use, but it does serve as a visual reminder that this is either a header included with the sketch (<code>""</code>) or an external library or system header (<code>&lt;&gt;</code>).</p>
