Arduino(C/C++) 除錯用 LOG巨集函數(LOG Macro Function)

Arduino(C/C++) 除錯用 LOG巨集函數(LOG Macro Function)

Arduino(C/C++) 除錯用 LOG巨集函數(LOG Macro Function) 


資料來來源: https://forum.amebaiot.com/t/arduino-ide/785

https://gist.github.com/xidameng/a433436921e0325426ea71303afc8dde


基礎版:

#define __DEBUG__

#ifdef __DEBUG__
	#define DEBUG(...) Serial.println(__VA_ARGS__)
#else
	#define DEBUG(...)
#endif


進階版:

#ifdef __DEBUG__
	// You should only uncomment 1 version at a time!
	// Version 1
	//#define DEBUG(...) Serial.println(__VA_ARGS__)
	// Version 2
	#define DEBUG(...) Serial.println(__VA_ARGS__); \
					   Serial.print(" @ [SRC]:      "); \
					   Serial.println(__FILE__); \
					   Serial.print(" @ [LINE]:     "); \
					   Serial.println(__LINE__); \
					   Serial.print(" @ [FUNCTION]: "); \
					   Serial.println(__func__); 
#else
	// else DEBUG is diabled
	#define DEBUG(...)
#endif

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *