Is it possible to make the selected [env] modify code parameters such as variables or pre-processor directives?
I’m thinking how to make say hardware pin definitions change automatically.
I thought they were for controlling the compiler, not the source.
The compiler can instrumentalize the source.
Consider
; common settings
[env]
platform = atmelavr
board = uno
framework = arduino
[env:uno_hw_variant_1]
build_flags =
-D HW_VARIANT_1
-D BLINK_TIME=500
[env:uno_hw_variant_2]
build_flags =
-D HW_VARIANT_2
-D BLINK_TIME=2000
And src/main.cpp
#include <Arduino.h>
#ifdef HW_VARIANT_1
#define LED 13
#elif defined(HW_VARIANT_2)
#define LED 12
#endif
void setup() {pinMode(LED, OUTPUT); }
void loop() {
digitalWrite(LED, HIGH);
delay(BLINK_TIME);
digitalWrite(LED, LOW);
delay(BLINK_TIME);
}
Depending on which env
you select, it uses a different pinout and blink speed.
That’s great. That’s exactly what I was looking for.
Cheers.