Most Google searches result in "array of function pointers in c", and very little for Arduino. Either these examples/explanations don't work on Arduino, the newer IDE can't handle array or function pointers, or I don't really understand array of function pointers. I have found this link from here:
http://forum.arduino.cc/index.php/topic,40842.0.html
This thread is ~5 years old and it doesn't seem to work with Arduino 1.0.3, or Arduino 1.0.5.
Does anyone know know how to structure array of function pointers for Arduino?
My application is a generic menu library, which would respond to GPIO input and display the button-navigated menu on a LCD/LCD-I2C.
So far, this is what I have, since I've just started a couple days ago and I'm stuck at the array of function pointers:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Bounce.h>
#define Button_1 9
#define LED_1 13
LiquidCrystal_I2C lcd(0x3F, 20, 4);
Bounce button_1 = Bounce(Button_1, 5);
void (*Page_1)(int foo);
typedef void (* GenericFP)();
GenericFP MenuFP[2] = {Page2, Page3};
int button_1_toggle = LOW;
void setup()
{
pinMode(Button_1, INPUT);
pinMode(LED_1, OUTPUT);
lcd.init();
lcd.backlight();
Page_1 = &Page1;
}
void loop()
{
toggle(&button_1, &button_1_toggle);
Page1(1);
switch(button_1_toggle)
{
case HIGH:
lcd.backlight();
break;
case LOW:
lcd.noBacklight();
break;
}
lcd.setCursor(0,0);
}
void toggle(Bounce* Button, int *ToggleValue)
{
if (Button->update())
{
if (Button->read() == HIGH)
{
if (*ToggleValue == LOW)
{
*ToggleValue = HIGH;
}
else
{
*ToggleValue = LOW;
}
}
}
}
void Page1(int foo)
{
};
void Page2(int foo)
{
};
void Page3(int foo)
{
};
Excuse the jumble. toggle() is a working function that takes input from a switch on pin D9 and toggles an LED on pin D13 and the LCD backlight.
The part that is not working is the array portion starting with the typedef. The typedef is based on the link above. The IDE is failing on:
GenericFP MenuFP[2] = {Page2, Page3};
The error message that is presented is "expected primary-expression before 'int'
These two lines are basically what is presented in the link but does not work with the newer IDE.
Any assistance is appreciated.
Thanks in advance.