Pointers to functions! HELP needed.

Hello,

I know that maybe this topic already exists but I didn't found it.
I am new to pointers and trying to find out how they work! The code is as follows :

void (*functii[2])(void);
char stare = 'o';

void setup()
{
  Serial.begin(9600);
  
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
}
void functie1(void)
{
  digitalWrite(13,HIGH);
  Serial.println("APRINS");
  functii[1] = functie1;
  functii[2] = functie2;
}
void functie2(void)
{
  digitalWrite(13,LOW);
  Serial.println("STINS");
}
void loop()
{
  
 if (Serial.available() > 0){
   stare = Serial.read();
   Serial.println(stare);
 if (stare == 'a')
 {
  functii[1];
 }
 else if(stare == 's')
{ 
  functii[2];
}
 }
 
}

My question: Is this not supposed to work?
Is there another way of using pointers?

Thank you!
:slight_smile:

  functii[1] = functie1;
  functii[2] = functie2;

You initialize the array in a function that is called by array access. That won't work. You need to initialize the array in setup(), BEFORE you try to call the functions.

By the way, array indices start at 0, not 1.

Thank you!

This small detail killed about 2 hours of my time. :slight_smile: