Optimizing Code Efficiency: Mastering Conditional Debugging with

Поделиться
HTML-код
  • Опубликовано: 7 сен 2024
  • Explore how to enable or disable "Serial.printf" statements for code debugging. We showcase the effectiveness of using #define, enabling these statements to stay in the code without compilation, ensuring zero impact on code execution time when debugging is unnecessary.
    //#define debug(fmt, ...)
    //#define debugLoop(fmt, ...)
    // Nano Version
    #define debug(fmt, ...) sprintf(buffer, fmt "
    ", ##__VA_ARGS__); Serial.print(buffer); // Nano
    #define debugLoop(fmt, ...) sprintf(buffer, "%s: " fmt "
    ", __func__, ##__VA_ARGS__); Serial.print(buffer); // Nano
    // ESP32 Version
    //#define debug(fmt, ...) Serial.printf(fmt "
    " ##__VA_ARGS__) // ESP
    //#define debugLoop(fmt, ...) Serial.printf("%s: " fmt "
    ", __func__, ##__VA_ARGS__) // ESP

Комментарии •