I am working on a fairly complex project with multiple fairly large subroutines, and I am looking for a simple way to sequence them using a simple add equation...
example
a1();
a2();
.
.
.
a18()
I would luv to replace it with something like
if (x>1){
x=x++;
a+x();
}
obviously the second one does not work, but it shows what I am looking for...
try this with your serial console opened at 115200 bauds
(typed here so might be buggy )
void a0() {
Serial.println(F("In function a0"));
}
void a1() {
Serial.println(F("In function a1"));
}
void a2() {
Serial.println(F("In function a2"));
}
void a3() {
Serial.println(F("In function a3"));
}
void a4() {
Serial.println(F("In function a4"));
}
void (*functionPointers[])() = {&a0, &a1, &a2, &a3, &a4}; // the & is not needed, I use it to show my intent of having the address of the function but you could write {a0, a1, a2, a3, a4}
const byte nbFunctions = sizeof(functionPointers) / sizeof(functionPointers[0]);
void setup()
{
Serial.begin(115200);
for (byte p = 0; p < nbFunctions; p++) functionPointers[p]();
}
void loop() {}
you should see in the console
In function a0
In function a1
In function a2
In function a3
In function a4
as a side note carefull with the ++ operator, you don't writex=x++ but just x++;if you want to increment x