Want to execute a function at a fix time interval, ticker doesn't work

08 Apr 2011

So I need to execute a function at a constant time interval. I don't think Ticker works because it doesn't take any input for the function. What happen if i want to execute a function with an argument at a fix time interval?

08 Apr 2011

Where's the input coming from? (thinking "Ticker", what would you expect the Ticker to pass to you when it calls back?)

08 Apr 2011

Thanks for a quick responds. It is a function that controls the stepper motor

The function has only input. But isn't it if i use the Ticker, there won't be any input or outputs?

Ticker timer;

function header void stepper_next_step (char mode);

timer.attach(&stepper_next_step,0.02);

it doesn't work.

08 Apr 2011

Make a small wrapper and pass it to the Timer:

void step_1()
{
  stepper_next_step(1);
}

ticker.attach(&step_1, 0.02);
08 Apr 2011

Thanks, Igor. That works! I never know or thought of doing such thing.

Now the next thing is whether i can change the period in real time? This is probably a lot harder to do on mbed, right?

And if it works, I'm pretty sure that's a completely different function, isn't it?

08 Apr 2011

Do detach, then attach with new interval.

08 Apr 2011

Awesome! This is wonderful! Thanks again, Igor!