I’m just switching over from the Arduino ide to PlatformIO.
So far so good, single ino files are not that hard to switch over.
However project with multiply ino’s is much harder to get compiled.
I have made this simple sample. The compiler keeps complaining WIFI was not declared in this scope
What am i doing wrong, what’s the correct place for #define WIFILED 32 so that you can use it globally.
You haven’t done a #include <WiFi.h> in the file where you are using the WiFi class.
You either solve the problem through clean C++ code or through global build flags. If you want to have a macro that needs to re-usable, do not put it in a .cpp file as you have done, but put it in a header file. E.g.,
Then include my_settings.h in each .c file where you use that macro.
The other way would be through build_flags = -D WIFILED=32 in the platformio.ini to define the macro in every invocation of the compiler. See docs. Solving it in the language as compared to in the build system should be your preferred way though.
You are also incorrectly mixing C and C++ code here. First, in this .c file, you are calling Arduino C++ APIs – that should be an immediate build error due to name mangling. I’m assuming you made a typo here and it’s actually myhelperfunction.c.
In C++, this can be constexpr. Marking it a constant expression also lets you do neat stuff like defining global constant variables with members initialized by calls to this function.