Comment/uncomment only a group of lines

Hi,
I have an Arduino sketch that gives quite a lot of output in the Serial monitor. I need these Serial.print() to know what the program is doing, for debugging purpose.
But I also need to read the Serial output on my computer with another software (R-Studio) to plot nice graphs .
I want to get rid of most of these Serial.print() when I read the output with R-Studio, so going back and forth bewteen this software and Arduino IDE forces me to comment/uncomment a lot of them every time. (And they are everywhere in my code, sometimes in the middle of command lines, so it takes forever).
Is there a feature that would allow to comment/uncomment a category of lines all at the same time, and leave the others unchanged?
Thanks
Aurélien

Comment one line:

// comment

comment the group of lines:

/*
operator1..
operator2..
*/

You could #define a value, let's call it debug, at the start of the sketch

#define debug

Then do this

#ifdef debug
  //conditional code goes here
#endif

The conditional code will be compiled into the sketch and executed only if debug is #defined

So changing a single line can be used to change many throughout the sketch

Thanks for your answer!
I had seen this syntax before, but I didn't know what it was.
The thing is, it is convenient when applied to a chunk of code, but it adds 2 lines for every line of code that you want to comment, and since I have a lot of small Serial.print() here and there, often in the middle of code lines, it makes it hard to read.
I guess you could also start the sketch with int debug= 0 or 1 and then write if debug= 0 or 1 and then put the commentable statement inside { }; it would save 2 lines.

Do you want to suppress all Serial printing or only some of it ?

If the former then obviously you could just find/replace Serial with //Serial and vice versa

If you only want to suppress some printing then write a function that prints what you pass it and call it to print the output. To suppress that printing add a return; as the first line of your printing function

Only some of it.
Yes I had thought about replacing Serial.print() by a function with a shorter name like p(), simply because writing it 150 times a day was annoying, but yes it's a good idea to do it for that goal.
I will try. Thanks!

Topic moved, you posted in the section for getting the IDE to work.

@aurelz

I'm using something like

#define  MODBUS_DEBUG  0     //!> Turn on debug statements to the serial output

#if MODBUS_DEBUG
#define DEBUG(...) Serial.print(__VA_ARGS__)
#define DEBUGLN(...) Serial.println(__VA_ARGS__)
#else
#define DEBUG(...)
#define DEBUGLN(...) 
#endif  

so I can write

DEBUG("Text");
DEBUG(aVariable);
DEBUGLN(anotherVariable, HEX);
DEBUGLN(F("Text with F-Makro"));

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.