(solved) Call a function by using a variable?

This is kind of hard to put into words exactly, '

What i would like to be able to do, is in one function, choose which function each zone will use, So that in this example, functionZone1 could be either blink(), dance(), or show() depending on what the user selected, the same thing for each zone.

Then, in another function, call a function with a variable.

I know this code won't work, but is it possible to something like this or should I head a different route (As i was typing this I came across a few problems with approaching it this way, but i'd still like to know if this is possible)...

void whichFunction();
{
functionZone1 = blink();
functionZone2 = dance();
functionZone3 = show();
functionZone4 = show();
}

void LEDshow() { 
for(int i = 0; i < LEDSinZONE1; i++) {
   functionZone1;
   leds[i] = value returned from blink() function, for each i 
   }
 for(int i = LASTzone1Pixel; i < LASTzone2Pixel; i++) {
   functionZone2;
  leds[i] = value returned from dance() function, for each i 
  } 
 for(int i = (LASTzone2Pixel); i < (LASTzone3Pixel); i++) {
   functionZone3;
   leds[i] = value returned from show() function, for each i  
 } 
 for(int i = (LASTzone3Pixel); i < ( LASTzone4Pixel); i++) {
   functionZone4;
   leds[i] = value returned from show() function, for each i 
  }    
}

This question does seem to be popular. :slight_smile:

Here is a reworked version I did a couple of weeks ago:

void func1 ()
 {
 Serial.println (1);
 }
 
void func2 ()
 {
 Serial.println (2);
 }

void func3 ()
 {
 Serial.println (3);
 }

void func4 ()
 {
 Serial.println (4);
 }

typedef void (*GeneralFunction) ();

// array of functions
GeneralFunction functionsArray [4] =
 {
 func1,
 func2,
 func3,
 func4,
 };

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  for (int i = 0; i < 4; i++)
    functionsArray [i] ();
  }  // end of setup

void loop () { }

The functions are stored in an array in this case. You select which one you want and call it.

Your code:

for(int i = 0; i < LEDSinZONE1; i++) {
   functionZone1;

That needs to be:

for(int i = 0; i < LEDSinZONE1; i++) {
   functionZone1 ();

The brackets are needed to call the function.

Well, that is surprisingly straight forward...