problem accessing a function from another .ino file

Hey guys

I’m trying to make a mode choser for my arduino so I can change the function of the button/pot depending on the mode I’m currently at. I intend to make 3 modes (drums, waves and sequencer), but right now I only have the drums

This is the main file:

#include <MozziGuts.h>        // at the top of your sketch
#include <RollingAverage.h>
#include "pitches.h"

#include <tables/cos2048_int8.h>
#define CONTROL_RATE 64   // or some other power of 2

const uint8_t POT_PIN = A5;
const uint8_t LDR_PIN = A1;
const uint8_t BUT_PIN = A3;
const uint8_t LED_PIN = 2;

int chosenMode = 0;

struct modeFunctions{
  void (*setup)();
  void (*samplePicker)(int c);
};

struct modeFunctions modes{
  drumsSetup,drumsChoice
};


RollingAverage<int,4> aLDR; //
RollingAverage<int,4> aPOT; //average from the last 4 samples, returned as int

void setup() { 
  pinMode(POT_PIN,INPUT);
  pinMode(BUT_PIN,INPUT);
  pinMode(LDR_PIN,INPUT);
  pinMode(LED_PIN,OUTPUT);
  digitalWrite(LED_PIN,HIGH);

  startMozzi(CONTROL_RATE);
  
}

#define tTime CONTROL_RATE * 4 //trigger time for mode change
void updateControl() {
  
  static uint16_t pot;
  static uint16_t ldr; 
  static uint8_t butTime = 0;
  static bool but;

  but = !digitalRead(BUT_PIN);
  pot = aPOT.next(mozziAnalogRead(POT_PIN));
  //mode control
  if (but) {
    butTime++;
  } else if (butTime > 0){
     if (butTime > tTime) {
      
    } else {
      butTime = 0;
    }
  }
  
}

int updateAudio() {
  // your audio code which returns an int between -244 and 243
  return 0;
}

void loop() {
  a

And this is the drums.ino:

#include <Sample.h>

#include "sample_kick.h"
#include "sample_vox.h"
#include "sample_snare.h"
#include "sample_hhopen.h"
#include "sample_hh.h"
#include "sample_clav.h"
#include "sample_clap.h"


Sample <sample_kick_NUM_CELLS, AUDIO_RATE> sKick(sample_kick_DATA);
Sample <sample_snare_NUM_CELLS, AUDIO_RATE> sSnare(sample_snare_DATA);
Sample <sample_clap_NUM_CELLS, AUDIO_RATE> sClap(sample_clap_DATA);
Sample <sample_hh_NUM_CELLS, AUDIO_RATE> sHihat(sample_hh_DATA);
Sample <sample_hhopen_NUM_CELLS, AUDIO_RATE> sHihatOpen(sample_hhopen_DATA);
Sample <sample_clav_NUM_CELLS, AUDIO_RATE> sClav(sample_clav_DATA);
Sample <sample_vox_NUM_CELLS, AUDIO_RATE> sVox(sample_vox_DATA);

void drumsSetup() {
  sKick.setFreq((float) sample_kick_SAMPLERATE / (float) sample_kick_NUM_CELLS);
  sSnare.setFreq((float) sample_snare_SAMPLERATE / (float) sample_snare_NUM_CELLS);
  sClap.setFreq((float) sample_clap_SAMPLERATE / (float) sample_clap_NUM_CELLS);
  sHihat.setFreq((float) sample_hh_SAMPLERATE / (float) sample_hh_NUM_CELLS);
  sHihatOpen.setFreq((float) sample_hhopen_SAMPLERATE / (float) sample_hhopen_NUM_CELLS);
  sClav.setFreq((float) sample_clav_SAMPLERATE / (float) sample_clav_NUM_CELLS);
  sVox.setFreq((float) sample_vox_SAMPLERATE / (float) sample_vox_NUM_CELLS); 
}

void drumsChoice(int c) {
  switch (c) {
    case 0:
    sClap.start();
    break;
    case 1:
    sHihatOpen.start();
    break;
    case 2:
    sKick.start();
    break;
    case 3:
    sSnare.start();
    break;
    case 4:
    sVox.start();
    break;
    case 5:
    sHihat.start();
    break;
    case 6:
    sClav.start();
    break;
  }
}

The problem I’m having is that I can’t seem to access the drumsSetup() function (nor the drumsChoice, for that matter). Now, I know that I don’t have a header file with the function prototypes, but I’ve read that if the .ino files are on the same folder you don’t need to make a header, as they become the same cpp.

I have attempt a few different approaches, and my last one was to use a pointer to the function, but I still get the “‘drumsSetup’ was not declared in this scope” error when I try to run the program. Any ideas?

I've read that if the .ino files are on the same folder you don't need to make a header, as they become the same cpp.

While that is true, the order of the data in the cpp file is still important.

ino files are joined in alphabetical order, not the order that the ino files are created.

but I still get the "'drumsSetup' was not declared in this scope" error when I try to run the program

Well, where IS drumsSetup() defined? Where is it called?

PaulS:
Well, where IS drumsSetup() defined? Where is it called?

Fair, fair, that was part of my attempts to fix the issue (Changing the function names), I changed the function names back to drumsSetup and drumsChoice, but it didn't help at all (I also corrected it in the main post).

Regarding the compile order, I knew it loaded the file with the same name as the folder first, then on alphabetical order, but would that mean that changing the place where I called drumsSetup() could fix the issue?

would that mean that changing the place where I called drumsSetup() could fix the issue?

Yes. Though it seems likely that you can't change where you call drumsSetup().

I still can't see a function called drumsSetup() nor can I see a call to drumsSetup().

PaulS:
Yes. Though it seems likely that you can't change where you call drumsSetup().

I still can't see a function called drumsSetup() nor can I see a call to drumsSetup().

The function is in the drums.ino file (The second one, line 20) where it's declared as "void drumsSetup() {...}"

The call to it is in the main file (line 19), inside the struct I've created (modeFunctions).

The modeFunctions struct has 2 components: A pointer to a void funtion with no arguments and a pointer to a void funtion with one int argument. The function names are then declared a few lines below where I declare a var with the struct I've created (modeFunctions) as its type.

In this case you have to add function prototypes in the beginning of the main ino file before you use them. The IDE is not clever enough to do that for you, even if those functions were defined inside the main ino file.

sterretje:
In this case you have to add function prototypes in the beginning of the main ino file before you use them. The IDE is not clever enough to do that for you, even if those functions were defined inside the main ino file.

You mean I need to add something like "void extern drumsSetup()"?

...
...

void drumSetup();
void drumChoice();

struct modeFunctions modes{
  drumsSetup,drumsChoice
};

...
...

Not tested; I don't think the 'extern' keyword is needed.

The call to it is in the main file (line 19), inside the struct I've created (modeFunctions).

You don't call a function by putting it's name or address in a struct. You might call the function indirectly by calling the function through its address, but you need to define where/how you are doing that.