typedef void (* GenericFP)(int); //function pointer prototype to a function which takes an 'int' an returns 'void'
GenericFP MenuFP[3] = {&Page1,
&Page2, &Page3}; //create an array of 'GenericFP' function pointers. Notice the '&' operator
void setup()
{
Serial.begin(115200);
}
void loop()
{
MenuFP[0](1); //call MenuFP element 0 with the parameter 1. This is equivalent to: Page1(1)
MenuFP[1](5); //call MenuFP element 1 with the parameter 5. This is equivalent to: Page2(5)
MenuFP[2](7); //and so on. This is equivalent to: Page3(7)
}
void Page1(int foo)
{
Serial.print("Page1=");
Serial.println(foo);
}
void Page2(int foo)
{
Serial.print("Page2=");
Serial.println(foo);
}
void Page3(int foo)
{
Serial.print("Page3=");
Serial.println(foo);
}