Here is one hint you might not have seen:
-
Every now and then we need to see if a certain section of code is running.
-
During debugging, we often use
Serial.print()to display a message or a variable's value. -
I always add a "Copy Tab" to my project sketches.
I have commonly used debugging lines of code in this Tab so I don't have to retype things. -
One such example is code to print how many times we reach a code section.
//Prints the number of times we have been at this location.
static unsigned int counter = 1; // <---<<<< D e b u g
Serial.print("Counter = "); // <---<<<< D e b u g
Serial.println(counter++); // <---<<<< D e b u g
//Prints the time it takes to return to this position. // <---<<<< D e b u g
static unsigned long startTime; // <---<<<< D e b u g
Serial.println(micros() - startTime); // <---<<<< D e b u g
startTime = micros(); // <---<<<< D e b u g
//Prints the time it takes to run this section of code. // <---<<<< D e b u g
static unsigned long startTime; // <---<<<< D e b u g
startTime = micros(); // <---<<<< D e b u g
//Section of code // <---<<<< D e b u g
Serial.println(micros() - startTime); // <---<<<< D e b u g
-
I add
<---<<<< D e b u gto the end of debug lines so they can be easily identified. -
Always remember, when we add debugging code to a sketch, it may effect that sketch, ex: might change timing.






