Okay, can't figure out what I'm doing wrong here but here's my code. When I try to compile it claims ModuleSet is not in the global scope, which it is. If I remove the function pointer part of the declaration it compiles fine.
// function is called inside another function higher up in the code
void calling_function()
{
ModuleSet("Loud", &LOUD_buzzer_use, &LOUD_buzzer_delay, &LOUD_buzzer_duration, &Sound_Buzzer);
}
// function declared down below like this
void ModuleSet( char* Title, byte *useThisModule, byte *delayThisModule, byte *durationThisModule, void (*testRunPtr)())
{
// actions
}
void Sound_Buzzer()
{
// buzzing
}
If I'm right you should declare a function before calling it. So Module_Set should be declare before using it in calling_function.
Or you can declare your functions in a header file included at the very beginning of your code.
I would think the same, however if I remove the function pointer part everything works fine. It has only become a problem now that I've tried to use a function pointer.
I think the problem is caused by the way arduino does its automatic prototyping on .pde files. If you define the function pointers in a separate .h file and include this it should work:
// test.h
typedef void (*testRunPtr )(void);
// sketch file
?
// function declared down below like this
void ModuleSet( char* Title, byte *useThisModule, byte *delayThisModule, byte *durationThisModule, testRunPtr )
{
// actions
}
// function is called inside another function higher up in the code
void calling_function()
{
ModuleSet("Loud", &LOUD_buzzer_use, &LOUD_buzzer_delay, &LOUD_buzzer_duration, &Sound_Buzzer);
}
void Sound_Buzzer()
{
// buzzing
}