i'm trying define array of function pointers, each function contains int
parameter. i'm trying set value of int parameter in array declaration
so have timed_task
struct, hold function pointer , value want pass
typedef struct { void (*proc)(int); int delaymsec; } timed_task;
then have array of timed_task
s this
static const timed_task attractsequence[] = { { lightson, 1000 }, { lightsoff, 500 }, { endsequence, 0 } };
and i'd call each of functions in turn, passing delay value each function. expect have wrong syntax (i'm still learning c). seemingly don't hit lightson()
routine @ all
void loop() // it's arduino project :) { attractsequence[sequence]; sequence++; } void lightson(int pause) { // not hit routine 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 wrong approach here, can see i'm trying achieve. advice welcome!
if want go through each item of attractsequence
once, can use:
void loop() { int count = sizeof(attractsequence)/sizeof(attractsequence[0]); (int = 0; < count; ++i ) { attractsequence[i].proc(attractsequence[i].delaymsec); } }
Comments
Post a Comment