I'm trying to define an array of function pointers, where each function contains an int parameter. I'm also trying to set the value of that int parameter in the array declaration
So I have a TIMED_TASK struct, that will hold the function pointer and value I want to pass
typedef struct
{
void (*proc)(int);
int delayMsec;
} TIMED_TASK;
Then I have an array of TIMED_TASKs like this
static const TIMED_TASK attractSequence[] =
{
{ LightsOn, 1000 },
{ LightsOff, 500 },
{ EndSequence, 0 }
};
And I'd like it to call each of those functions in turn, passing the delay value to each function. This is where I expect I have the wrong syntax (I'm still learning C). I seemingly don't hit my LightsOn() routine at all
void loop() // It's an arduino project :)
{
attractSequence[sequence];
sequence++;
}
void LightsOn(int pause)
{
// I do not hit this routine for some reason?
Serial.print("LIGHTS ON");
Serial.print(pause);
}
void LightsOff(int pause)
{
Serial.print("LIGHTS OFF");
Serial.print(pause);
}
It's entirely possible I'm taking the wrong approach here, but hopefully you can see what I'm trying to achieve. Any advice very welcome!
Serial.print(pause)is invalid c, not entirely invalid but as it is in your code it seems to be. Also, you are never calling the function through the pointer, where do i expect it to be called in the posted code?