如何使用预处理器判断是否使用 Arduino 框架 (PlatformIO)
你可以使用 如何在 PlatformIO 中打印所有预处理器标志 打印预处理器标志。注意这些包括 #include 如 Arduino.h 中 #define 的标志。但你可以从 main.cpp 中删除所有内容,这样只有构建环境定义的标志可见。
Arduino 相关标志是
arduino_preprocessor_check.txt
#define ARDUINO_VARIANT "esp32"
#define ARDUINO_ARCH_ESP32 1
#define ARDUINO_PARTITION_default 1
#define ARDUINO 10812
#define ARDUINO_ESP32_DEV 1
#define ARDUINO_BOARD "Espressif ESP32 Dev Module"所以如果你想要平台无关的 Arduino 检查,使用
arduino_preprocessor_check.cpp
#ifdef ARDUINO
// Arduino code goes here
#else
// Non-Arduino code goes here
#elseCheck out similar posts by category:
Arduino
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow