I
I
Ilya Plotnikov2014-06-26 16:47:35
Arduino
Ilya Plotnikov, 2014-06-26 16:47:35

How to change callback in SimpleTimer Arduino?

I use the library playground.arduino.cc/Code/SimpleTimer
as a timer There was a need to change the callback for some timers. The problem is that you have to disable the timer and create a new one with a different callback. In code, this solution looks cumbersome.
Is it possible to create a variable and write the name of the function for setInterval into it, and then just change the value of this function?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slipeer, 2014-06-26
@ilyaplot

You can specify a function in the callback that will pull another function by the pointer.
The pointer is global - redefine it if necessary.
An example of working with function pointers:

void start(char* p) {
Serial.println(p);
}
 
void (*Write)(char*);
 
void setup()
{
Serial.begin(9600);
Write = &start;
(*Write)("I've started, yeah! :)");
}

void loop()
} 
}

Where (*Write)(char*) is a pointer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question