You simply tell a piece of code what function you want to use when it wants to do something. It just stores that function in a variable. And once the piece of code thinks it needs to use that function it can call it.
It's a bit like ISR on the Arduino with attachInterrupt() but it is not a ISR. That just stores the function name you pass it. And the real ISR calls that function (by reading the variable) when it's fired.
But every function can call a variable other function. And if it's used when a condition is met it's often called a call back ![]()
void (*functionPointer)(void);
void setup() {
Serial.begin(115200);
functionPointer = &testFunction;
}
void loop() {
functionPointer();
}
void testFunction(){
Serial.println("TEST!!");
}