For debugging I have a lot of Serial.print()s in my sketch.
Is there a difference in operation and/or run time if the cable to the IDE/Serial Monitor is connected or not?
For debugging I have a lot of Serial.print()s in my sketch.
Is there a difference in operation and/or run time if the cable to the IDE/Serial Monitor is connected or not?
Even better system for switching debug output on and off:
#define DEBUG true //set to true for debug output, false for no debug ouput
#define Serial if(DEBUG)Serial
Add this to setup() if you are using a Leonardo, Pro Micro, or other ATmega32U4 based board and don't want the program to run until the Serial Monitor has been opened while debug output is enabled:
while (DEBUG && !Serial);
Then you can just use Serial functions as usual in the rest of your sketch.
If you have debug and non debug serial output or want multiple levels of output possible you can do something like this:
#define DEBUG_ERROR true
#define DEBUG_ERROR_SERIAL if(DEBUG_ERROR)Serial
#define DEBUG_WARNING true
#define DEBUG_WARNING_SERIAL if(DEBUG_WARNING)Serial
#define DEBUG_INFORMATION true
#define DEBUG_INFORMATION_SERIAL if(DEBUG_INFORMATION)Serial
void setup() {
Serial.begin(9600);
while (!Serial);
DEBUG_ERROR_SERIAL.println("This is an error message");
DEBUG_WARNING_SERIAL.println("This is a warning message");
DEBUG_INFORMATION_SERIAL.print("The state of pin 5 is ");
DEBUG_INFORMATION_SERIAL.println(digitalRead(5) ? "HIGH" : "LOW");
Serial.println("This is standard program output");
}
void loop() {}