[SOLVED] Need Help SimpleTimer

good day !! how many void ****() can simpletimer handle in the same time…

this my timer.interval code. all of them run perfectly except the last one ( ph sensor) any solution ?

 timer.setInterval(1000L, humiditySENSOR);
  timer.setInterval(1000L, ldrSENSOR);
  timer.setInterval(1000L, soilSENSOR);
  timer.setInterval(1L, fanLED);
  timer.setInterval(1L, lampLED);
  timer.setInterval(1L, plantpumpLED);
  timer.setInterval(1L, aquapumpLED);
  timer.setInterval(1L, manualMODELED);
  timer.setInterval(1000L, foodlevelPUMP);
  timer.setInterval(1000L, waterlevelPUMP);
  timer.setInterval(1000L, phSENSOR);

10 as maximum each timer
You can use timer2, timer3 an so on…10 intervals each

1 Like

oh thanks @psoro

Sorry if I post wrong place. Does Simple Timer work with parameters of function?

Is 1ms really needed for these 5 timers? I think you are asking for trouble.

What does that translate to in English?

http://playground.arduino.cc/Code/SimpleTimer

like
void function (int a, int b)
{

}

It wouldn’t be int a, int b as the parameters are a long and a function name.

To be safe I would say don’t even think about it, use it as per the docs.

I think he wants to add a parameter in the timer setup, e.g timer.setInterval(1000, function(parameter));

But that does not work :slight_smile:

I think you are right but he / she can have:

timer.setInterval(longvariable, function);

As you know SimpleTimer, despite the name, is very powerful. Stop, start, enable etc, etc.

You can probably change the function too but it is probably much easier just to kill a timer and initiate a new one.

1 Like

You can change the array sizes in the SimpleTimer library code and recompile it to provide as many timers as you need, but perhaps using a second timer object to provide 10 more timers is easier.

There are any number of uses for timers that can deliver a ‘message’ to the callback function, such as one callback that could handle several similar buttons, LEDs, or whatevers. There is a library similar to SimpleTimer, called ‘Timer’ that takes an unsgined int argument which it eventually passes to the callback function. (Of course, each timer’s storage must increase 2 bytes due to that.) I’ve modified my library’s SimpleTimer to take & pass a byte argument, solely because SimpleTimer is currently better known (and because I could live with 8-bit messages).

I think I can do it with global variable, function x (param a, param b) inside function y, param a, b asign to global variable c, d blah, blah… and than asign function y into Simple Timer. Is it possible?

Probably. It sounds like it could work, but you never know until you try :wink:

Just happened across this thread. The original author of SimpleTimer and I upgraded the original SimpleTimer code so the called functions can take a void pointer. A void pointer can be cast to an int, char, etc or to the address of a structure holding more information (take care here, the referenced data must still be in scope). The upgraded code can be found at:
https://github.com/marcelloromani/Arduino-SimpleTimer/tree/feature/simpleTimerPlus/SimpleTimer
The upgrade adds this feature. The original functionality is still there.
Regards
-Bill K
ROSoftWare

This is an older topic and much has changed.

Blynk has recently merged a modified version directly into Blynk so external SimpleTimer library is not required (and will just be ignored). I don’t know if it supports the referenced void pointer… @vshymanskyy ?

Great. We will certainly update it. Thanks!

The merged version of SimpleTimer appears to be just a rename and does not support args to the callback functions. It even references the SimpleTimer documentation at http://playground.arduino.cc/Code/SimpleTimer for usage. The updated version of SimpleTimer which does support args to the callback functions and is also backwards compatible with the current usage is available at https://github.com/marcelloromani/Arduino-SimpleTimer/tree/master/SimpleTimer.
Regards
-Bill K
R O SoftWare

1 Like