Error after moving functions to different tabs "Compilation error: 'PROGRAM_LED_IDEL_PUMP_UP' was not declared in this scope"

I am trying to organize my code.
I am trying to figure out depending stuff in my code and moving it into different tabs in my arduino project.

I am currently trying to move a function out of my main sketch into a separate sketch. Then i want to move more functions and after I moved all functions I want ti simply them.

Now when I moved one function into a different tab i get the following compilation error of the IDE
Compilation error: 'PROGRAM_LED_IDEL_PUMP_UP' was not declared in this scope

do i have to tell the IDE when and where to include the function in different tabs?

Just comment in and out the following function:

void PROGRAM_LED_IDEL_PUMP_UP(DM13A_LedSegment LedSegment, NextExcecutionTime &functionCycleTimer, bool reset = false)

either in the first main tab or in the led functions tab.
2024_07_19_Ghostbuster_ProtonPack.zip (5.5 KB)
DM13A.zip (2.8 KB)
NextExcecutionTime.zip (559 Bytes)
Button-1.0.0.zip (5.5 KB)
dyplayer-main.zip (30.1 KB)
FastLED-3.6.0.zip (509.0 KB)

See My Post #5 in this Thread for a basic guide to breaking large projects into smaller modules.

BTW, many people here will not download .zip files of unknown provenance.

1 Like

hey thank you, so what is a better way to provide the files? plain text?
For my question I already moved other function to different tabs and it worked without any compiling issues.

Simply moving functions between ino files in tabs is a childish approach and you will very quickly find that this does not work on serious programs. You will spend a lot of time trying to solve problems with functions and variables from one tab not being visible in another.
It’s better to learn to do everything right right away.

Post the code inline with Code Tags per the Forum's instructions:

I do download zips :wink: But I'm not downloading 6 zips with the risk of not knowing how to combine them after extracting. If you zip your complete project (the sketch directory) in one zip it's a lot easier.

Note that I only can (and will) check code for AVR based boards so also let me know which board you're using.

hey the project is right in the first zip the proton pack zip file. for compiling i use the arduino nano board.

the other zip files are the classes i created and the stuff i downloaded from the weg for controlling the button inputs, neopixel leds and the soundchip.

I did download the zips, created a fresh portable install of IDE 1.8.19, imported the ZIP libraries and compiled your GhostBuster sketch without problems.

Not sure what is wrong at your side.

thank you very much.

and now if you comment out the function "PROGRAM_LED_IDEL_FIRING" in the main sketch from line 177 to 188 and move it to the tab "Led_functions.ino"

then the code does not compile anymore.
Then you should get the following compiling error below:

That's what I don't understand, maybe when I move the function to a different tab and try to compile the compiler includes this code portion to early in the main ino sketch.

C:\Users\jensh\OneDrive\Desktop\2024_07_19_Ghostbuster_ProtonPack\2024_07_19_Ghostbuster_ProtonPack.ino: In function 'void loop()':
C:\Users\jensh\OneDrive\Desktop\2024_07_19_Ghostbuster_ProtonPack\2024_07_19_Ghostbuster_ProtonPack.ino:313:27: error: 'PROGRAM_LED_IDEL_FIRING' was not declared in this scope
   if(SW_Intensify.read()) PROGRAM_LED_IDEL_FIRING(BarGraph_Segment, barGraphFire);
                           ^~~~~~~~~~~~~~~~~~~~~~~
C:\Users\jensh\OneDrive\Desktop\2024_07_19_Ghostbuster_ProtonPack\2024_07_19_Ghostbuster_ProtonPack.ino:313:27: note: suggested alternative: 'PROGRAM_LED_IDEL_PUMP_UP'
   if(SW_Intensify.read()) PROGRAM_LED_IDEL_FIRING(BarGraph_Segment, barGraphFire);
                           ^~~~~~~~~~~~~~~~~~~~~~~
                           PROGRAM_LED_IDEL_PUMP_UP

exit status 1

Compilation error: 'PROGRAM_LED_IDEL_FIRING' was not declared in this scope

There are very few that know what the IDE exactly does. There is a process called the arduino builder and we know what it is supposed to do and we can point out where it miserably fails.

The arduino builder (IDE) creates one big file from all ino files. It starts with the file that has the same name as the holding dirtectory and next appends all other ino files to the the end in alphabetical order. That is the file that is passed to the compiler.

The arduino builder is also supposed to add function prototypes in the right place in the final file.

The result of this will be a file with the double extension .ino.cpp.

When the compiler encounters a call to a function (e.g. to PROGRAM_LED_IDEL_PUMP_UP()) the compiler needs to know what the arguments and return value of that function are.

If you look at your original that I successfully compiled, PROGRAM_LED_IDEL_PUMP_UP() is defined before it is used in loop().

When you did split your main code it will be after loop (as mentioned above) and hence the compiler does not know about it.

For the given problem you can add a so-called function prototype before the first function in your main code.

...
...
const int L_SlowBlow = 5;

const int brightnessMax = 180;  // % brightness = x%+254/100
const int interval = 3500;      // 5 seconds

// sterretje: function prototype
void PROGRAM_LED_IDEL_PUMP_UP(DM13A_LedSegment LedSegment, NextExcecutionTime &functionCycleTimer, bool reset = false);

void SlowBlowLed_Boot() {
  for (int i = 0; i <= brightnessMax; i++) {
    int pwmValue = pow(2, i / 32.0) - 1;  // Logarithmic scale
    analogWrite(L_SlowBlow, pwmValue);
    delay(interval / brightnessMax);
  }
}

...
...

The IDE is supposed to add this prototype for you but it did not (or put it in the wrong place). And hence your problem.

To find what the compiler actually compiles, you can enable verbose output during compilation under file/preferences in the IDE. If the IDE gets to the point where it has created this big sketch file, you will be able to find a file called something like yourSketch.ino.cpp. You can search the verbose output (easiest to copy it to a text editor) and search for .ino.cpp.

Below the result for your code where a function was moved; note the .ino.cpp near the end of the second line.

...
...
Detecting libraries used...
/home/wim/Downloads/1_arduino_ide_1.x/arduino-1.8.19-1284188_error_moving/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/wim/Downloads/1_arduino_ide_1.x/arduino-1.8.19-1284188_error_moving/hardware/arduino/avr/cores/arduino -I/home/wim/Downloads/1_arduino_ide_1.x/arduino-1.8.19-1284188_error_moving/hardware/arduino/avr/variants/eightanaloginputs /tmp/arduino_build_514557/sketch/2024_07_19_Ghostbuster_ProtonPack.post09.ino.cpp -o /dev/null
...
...

Note that the given solution works for this specific problem; it might not work for all problems that you will encounter with multiple ino files. In that case you have to use .h and .cpp files.

1 Like

thank you for the work you did and the time you invested in telling me how the ide handles the sketches and tries to compile them as well as how to tackle the issue.

so i think the cleanest way will be to stay in the main file and after my code is complete and everything works i can try to separate it into different header and cpp files.

is there a solution to include header files right out of my sketch folder?
otherwise i always have to edit the header and cpp files in the my documents arduino folder.

additional:
or i create tabs with a letter and underscore so that the ide will include the functions in the same order they should appear in the main ino file.

Not sure what that means. But, you can create both .h and .cpp files right in the Arduino IDE ... just like .ino files.

okay and how to include?
as for now i created h und ccp files, zipped them and then added the zip to the ide library.

What does that mean?

Which version of the Arduino IDE are you using?

when i use the #include „sample.h“ the ide includes the header file that i located in the user specific documents arduino folder on my windows c drive.

my question is how or if i can include header files from other locations if my drive.

No, it doesn't. #include "FileName.h will look first in the sketch folder you're currently working with ... meaning the the same place as the .ino file is stored.

Let me try asking this a final time before I leave this thread for good.
Which version of the Arduino IDE are you using?

version 2.3.2

sorry i didn‘t know that the ide will search the sketch folder first.

so that means if i have a newer version with the same name in my sketch folder it‘ll include this one instead of the one in the arduino folder?

with this knowledge i could have prepared the whole project in the first place.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.