turning debug "Serial.print" messages on/off via a digital input?

I have some code with a lot of “Serial.print” commands I use for debugging but it would be nice to be able to turn these on or off as required - say via a DIP switch or jumper?

Is there a way to achieve this as they are spread out all through my code and hunting them down to manually comment them out is a pain!

Thanks :slight_smile:

Hello,

What is your problem exactly, because what you are asking is very easy

if ( digitalRead ... )
  Serial.print ...

Make a function or macro so that you don't have to add this check manually for every debug messages

yeah of course - der - i was overthinking it!! :( :zipper_mouth_face: :roll_eyes:

I was looking at:

define DEBUG

&

ifdef DEBUG

etc and trying to work out how to turn that on and off with a digital pin.

define DEBUG

&

ifdef DEBUG

Of course you know this is looked at by the pre-processor only.

Yes - hence why I was struggling to work out how to do what i wanted - over thinking it all! :-/