Blynk Timer Questions

Just a quick question about Blynk Timer. In the process of updating my sketch and I was advised to change from Simple Timers to Blynk Timers. All that said, do I still need to have; in the main loop, or are those functions now covered by the; call?

void loop()

Also, I notice there isn’t a lot of threads on the subject, so if others wish to jack this thread to ask other related questions, I’m fine with that.

Someone correct me if I’m wrong…
But blynktimer is simpletimer, just with another name, and a bit expanded (some expansion by myself). It’s included in the libraries for blynk.

You still need to use it the same way as you would the standard simpletimer library

I.e. Declarations, setinterval and .runs


Yes, as @Fettkeewl said… same only different :wink: It works the exact same way, but without needing to include a separate library… and while possibly works either way, change from SimpleTimer timer; to BlynkTimer timer; in pre-setup.

And of course, a single BlynkTimer object allows to schedule up to 16 timers, instead of only 10.

Thanks guys. FWIW, I had to omit #include <SimpleTimer.h> to get it to run. I just didn’t know if leaving the loop as is was syntactically correct or not.

I changed this to a FAQ category for any other users.

BlynkTimer enables you to perform periodic actions in the main loop() context.
It is the same as widely used SimpleTimer, but fixes several issues.
BlynkTimer is included in Blynk library by default, so no need to install SimpleTimer separately or include SimpleTimer.h

1 Like

Also notice, in blynktimer there is now a function to change intervals on running timers so long as they are of the type that runs forever, ie setup with setinterval, without x number of runs!

Timer.changeInterval(timerID, millis as long)

Dear Sir,
can you give us an example regarding this new function? I did not get in…

Function is declared as such, returns true on successful change. I.e provided timerID is for an existing timer that is of the type “runs forever”

// updates interval of the specified timer
    bool changeInterval(unsigned numTimer, unsigned long d);

All it does is change the update interval of a previously set timer.

Blynktimer timer;
int timerID;

void setup 
   // do myFunc every 5 seconds 
   timerID = timer.setInterval(5000L, myFunc);
   // oh crap I changed my mind, do myFunc every second instead 
   timer.changeInterval(timerID, 1000L);

// some function
void myFunc() 


super fine explanation, thanks a lot !!!

hi.what does mean parameter ‘p’?thanks

// Timer will call function ‘f’ with parameter ‘p’ every ‘d’ milliseconds forever
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setInterval(unsigned long d, timer_callback_p f, void* p);

Presumably you can give a parameter to the function.

   timer.setInterval(1000L, thisFunction, param.asInt());

It’s something I’ve been waiting for, if it works as I described, but I can’t test it now, so it’ll probably take some trial/error to get it going :wink:

I am sorry I bumped up this conversation. BUT, I can confirm that you really can pass arguments to the callback function with blynkTimer’s methods (.setTimeout, at least). Just create a pointer to your variable and add it as an argument:

static int number = 7;
int *p = &number;|
timer.setTimeout(3000L, printNumber, p);|

The variable itself needs to be of static type. Then in the callback function, void pointer needs to be type casted to the original variable data type:

void printNumber(void *p){
Serial.print("This should be seven: ");
Serial.println(*(int *)p);