Using OLED display functions in multiple cpp files

I am coming from the standard Arduino IDE world and just installed platformIO.

in my main.cpp file I included all the libraries I want to use (eg: Adafruit_SSD1306.h) and in the setup function I initialize it with display.begin(SSD1306_SWITCHCAPVCC, 0x3C);, I clear the display and write some welcome text.

After this I’d like to move forward with displaying more content. This routine involves lots of WIFI communication and complex enough to not be the part of the main.cpp file, so I have created another file called myWifi.h. In this one I’d like to continue using the already initialized display, for example: display.println(“Hello world”);

During the compilation I got the following error message: src\myWifi.h:16:3: error: ‘display’ was not declared in this scope

The approach I described above worked completely fine with the standard ArduinoIDE, but drops me this message with platformIO. Would you mind highlighting how should I solve this problem?

thanks!

I suppose you use INO files with Arduino IDE. So, Arduino IDE concatenates all INO files into the one main.cpp. You can do the same with PlatformIO.

Add #include <Arduino.h> to your myWifi.h at the top of file.