I like to use this so I can quickly stop all the Serial.Print lines outputting by uncommenting the top line and commenting the second line, for ESP32 like this and it works
//#define debug(fmt, ...)
#define debug(fmt, ...) Serial.printf("%s: " fmt "\r\n", __func__, ##__VA_ARGS__) // ESP
For the nano, I seem to have to change this slightly because Serial.printf is not supported, so I have to use sprintf first...
The question is, why does debugLoop correctly apply the number 95 to the output, but debug does not.
What am I messing ?
char buffer[60];
//#define debugLoop(fmt, ...)
#define debugLoop(fmt, ...) sprintf(buffer, "%s: " fmt "\r\n", __func__, ##__VA_ARGS__); Serial.print(buffer); // Nano
//#define debug(fmt, ...)
#define debug(fmt, ...) sprintf(buffer, fmt "\r\n"); Serial.print(buffer); // Nano
void setup() {
Serial.begin(115200);
}
void loop() {
debugLoop("my number is %d", 95); // Outputs loop: my number is 95
debug("my number is %d", 95); // Outputs my number is 459
while (true);
}
Output:
loop: my number is 95
my number is 459