By “Arduino” you mean like an Arduino Uno here?
Read through the documentation at “platformio.ini” (Project Configuration File) — PlatformIO latest documentation.
You can have multiple available environments with the same code base. But you can also differentiate the code based on the target. E.g.
[platformio]
;default_envs = uno, esp32
[env:uno]
platform = atmelavr
board = uno
framework = arduino
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
will give you two environments to work with. You can compile each seperately or all of them (the default environment, which is by default “all”, but also selectible via default_envs
).
In the code you can work with #ifdef <macro>
to check wether it’s compiling for a specific target. You can put the macros in yourself via build_flags
(see docs) or rely on pre-included macros like ARDUINO_ARCH_ESP32
etc.
so in C++ code we can do
#include <Arduino.h>
#ifdef ARDUINO_ARCH_ESP32
#define BLINKY_PIN 2
#else
#define BLINKY_PIN 13
#endif
void setup() {
pinMode(BLINKY_PIN, OUTPUT);
}
void loop() {
//...
}