BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

New, simplified periodic actions API

#1

I just added this to the master branch on github, and it will hopefully be available with the next release (v0.5.0). The intention is to have a simpler way to create periodic actions (currently SimpleTimer/BlynkTimer method is rather unintuitive).

Usage:

void loop() {
  ...
  BLYNK_EVERY_N_MILLIS(500) {
    Serial.println("Woa!!!");
  }
  ...
}

Supported variants:

  • BLYNK_EVERY_N_MILLIS(ms)
  • BLYNK_EVERY_N_SECONDS(sec)
  • BLYNK_EVERY_N_MINUTES(min)
  • BLYNK_EVERY_N_HOURS(hour)

Please try it out and tell me how it works with your hardware. Any other feedbacks/ideas are welcome!
Cheers!

1 Like

pinned #2
0 Likes

#3

the idea is interesting. i have 3 observations (so far):

  • shorter name, like:
    TIMER_SECONDS(sec) {}```
    

etc

  • these functions should be declared outside of any functions, like the BLYNK_WRITE(xx) {} and BLYNK_READ(xx) {}, this way one could have a “clean” loop.

  • how can one enable / disable a timer, or modify the frequency? or ms, sec, min, hour will be a standard global variable, and it is possible to change them on the fly?

1 Like

#4

Thank you @wanek. Great ideas, I will think if it can be implemented somehow.

0 Likes

#5

Don’t forget the ever so popular do once after x Millis, meaning setTimeout :slight_smile:

0 Likes

#6

@Fettkeewl could you describe your vision how to use it with this syntax?

0 Likes

#7

I’ve read your BlynkEveryN.h briefly and have yet to understand it all :stuck_out_tongue:

I’m just envisioning something like
BLYNK_ONCE_N_MILLIS(ms)
BLYNK_ONCE_N_SECONDS(sec)
etc

Supply the time, internally its tracked untill it has executed once then dispose. Same principle in BlynkTimer altough I can’t at the moment see how it is replicable in your class. :slight_smile:

0 Likes

#8

It is not, afaik.

0 Likes

#9

Which part? The internal tracking?

0 Likes

#10

In my opinion, setTimeout can not be replicated with a similarly easy syntax… :frowning:

0 Likes

#11

Alright I’ll take your word for it :smiley:

0 Likes

#12

@Fettkeewl, however something like this (or similar) could work:

where “some_variable > 10” is the condition to (re-)start this timeout timer.
The main problem with this, as well as with BLYNK_EVERY_N_*, that it will ONLY work inside of the loop(), and not inside of any if(). Microcontroller has to step on this construction frequently so it can verify if it needs to run the timer code.

2 Likes