With a platformio.ini
of
[env:heltec_wifi_kit_32]
platform = espressif32
board = heltec_wifi_kit_32
framework = arduino
lib_deps =
olikraus/U8g2 @ ^2.28.8
fastled/FastLED @ ^3.3.3
The error message for your program reads
Indexing .pio\build\heltec_wifi_kit_32\liba1b\libWire.a
In file included from src\main.cpp:13:0:
src\marquee.h: In function 'void DrawMarquee()':
src\marquee.h:15:9: error: 'g_LEDs' was not declared in this scope
g_LEDs[i] = c.setHue(k+=8);
^
src\marquee.h:21:9: error: 'g_LEDs' was not declared in this scope
g_LEDs[i] = CRGB::Black;
^
src\main.cpp: In function 'void loop()':
src\main.cpp:58:11: warning: unused variable 'initialHue' [-Wunused-variable]
uint8_t initialHue = 0;
^
src\main.cpp:59:17: warning: unused variable 'deltaHue' [-Wunused-variable]
const uint8_t deltaHue = 16;
^
src\main.cpp:60:17: warning: unused variable 'hueDensity' [-Wunused-variable]
const uint8_t hueDensity = 8;
^
which tells you exactly what’s wrong: the global variable g_LEDs
is unknown in the function DrawMarquee()
. When you look at the code, you write:
So you first pull in the function code that uses g_LEDs
and then you actually declare and create the g_LEDs
variable. So, at the position in which DrawMarquee()
is defined, there is no mention of the global variable g_LEDs
before that.
An extremely cheap way to fix that is to simply declare the global variable before you use it, i.e. reverse the order of the #include
line and the one below. Then you get
Building .pio\build\heltec_wifi_kit_32\firmware.bin
Checking size .pio\build\heltec_wifi_kit_32\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 5.5% (used 18148 bytes from 327680 bytes)
Flash: [== ] 20.8% (used 272662 bytes from 1310720 bytes)
esptool.py v2.6
========================= [SUCCESS] Took 17.16 seconds =========================
However I don’t consider that a proper fix, since global variable sharing accross files is not done according to best practices at all. This forum already has a lot of info on splitting source code files and the associated techinques with sharing global variables: Tutorial for creating multi cpp file arduino project
I can also give my reference solution for that problem. The basic technique is:
- declare global variables as
extern ...
in a header file - split code into header file and implementation file