简体   繁体   中英

Verbose debug printing in arduino?

I'd like to have some sort of verbose debug printing in arduino that can be enabled/disabled by a flag. For example I'd like the ability to do something like

#define VERBOSE
#define VERBOSE_PRINT(text) #ifdef VERBOSE Serial.println(text); #endif

Later in code:

VERBOSE_PRINT("Doing something");

if VERBOSE is defined then I should get stuff out over the serial port and if it's not defined then that code won't be compiled. Unfortunately this isn't working. I get the error: "error: '#' is not followed by a macro parameter". So I'm wondering what's the best way to get an optionally compiled print (or anything for that matter). Of course I could manually write out the #ifdefs, but I'd like it streamlined so that it doesn't take up a ton space and so I don't have to write it out each time I'd like to use it. Is a function w/ the #ifdef inside the function the best way to do this?

#define VERBOSE

#ifdef VERBOSE
#define VERBOSE_PRINT(str) Serial.println(str)
#else
#define VERBOSE_PRINT(str)
#endif

VERBOSE_PRINT("Doing something");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM