I need to define an array, that later on will be the name of a class, and will be pointed to.
For example (in a non pre-processor way):
const char *button_names[4]={"b0","b1","b2","b3"};
and later on (when it will be define in pre-processor), in a function it will be called as :
static Button2 button_names[i]
How can I define it that array to be in pre-processor?
Edit2:
Button2 *Buttons[8] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}; // Here I use an optional up to 8 Buttons.
and later on, after I read parameter file: i get the numSW
/* Below example is only to check if I can use such technique - I know it is not a good coding. Example here is only for up to 4 Buttons*/
void init_buttons()
{
for (uint8_t i = 0; i < numSW; i++)
{
if (i == 0)
{
static Button2 bt1;
Buttons[i] = &bt1;
}
else if (i == 1)
{
static Button2 bt2;
Buttons[i] = &bt2;
}
else if (i == 2)
{
static Button2 bt3;
Buttons[i] = &bt3;
}
else if (i == 3)
{
static Button2 bt4;
Buttons[i] = &bt4;
}
Buttons[i]->begin(buttonPins[i]);
if (buttonTypes[i] == 0) /* On-Off Switch */
{
Buttons[i]->setPressedHandler(OnOffSW_ON_handler);
Buttons[i]->setReleasedHandler(OnOffSW_OFF_handler);
}
else if (buttonTypes[i] == 1) /* Momentary press */
{
Buttons[i]->setPressedHandler(toggle_handle);
}
Buttons[i]->setID(i);
}
}
new