Skip to content

Function pointer interrupt Handler #39

Answered by rlogiacco
AbbottF asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, there’s no reason why you shouldn’t! You just declare a buffer of your type, which is going to be the function reference of your choice:

typedef void (*func)();
CircularBuffer<func,100> functions;

void a() {}

void b() {}

void c() {}

void setup() {
  functions.push(a);
  functions.push(b);
  functions.push(c);
}

Please, note I haven’t compiled the code above, I just pulled it out while on the go, it’s just a reference to describe how you can do it.
Also, by varying the typedef you can establish input parameters and return values: you are not limited to functions without parameters or return values, but they must all comply with the same interface.

Replies: 7 comments 16 replies

Comment options

You must be logged in to vote
3 replies
@AbbottHMG
Comment options

@rlogiacco
Comment options

@AbbottHMG
Comment options

Answer selected by rlogiacco
Comment options

You must be logged in to vote
4 replies
@rlogiacco
Comment options

@AbbottHMG
Comment options

@AbbottHMG
Comment options

@rlogiacco
Comment options

Comment options

You must be logged in to vote
4 replies
@AbbottHMG
Comment options

@rlogiacco
Comment options

@rlogiacco
Comment options

@AbbottHMG
Comment options

Comment options

You must be logged in to vote
3 replies
@rlogiacco
Comment options

@AbbottHMG
Comment options

@rlogiacco
Comment options

Comment options

You must be logged in to vote
1 reply
@AbbottHMG
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@rlogiacco
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants