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

Arguments function in timer

setInterval does not accept a function with arguments as the second parameter, for example:

timer.setInterval (1000L, someFunction (int a, int b));

I need to run a function with arguments at certain intervals, how can I do this?

@jojoboy please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

Hope this can help :

there is no answer to my question, apparently it will not be possible to solve this with the help of BlynkTimer

Can you tell me what are you trying to do exactly ?

You should use it like this…

void setup()
{
timer.setInterval (1000L, someFunction);
}

void someFunction() 
{
int a;
int b;
bla....bla.. 
}

Im need to do like this

BlynkTImer timer;
void someFuncition(int a,int b)
{
Serial.pirntln(a+b); // for example
}

void setup (){
timer.serInteraval(1000L,someFunction(1,2));
}
void loop (){
timer.run();
}

but I cannot do this, I found function like


    int setInterval(unsigned long d, timer_callback_p f, void* p);

but I dont understand how it work

Try this :

BlynkTImer timer;

int a;
int b;

void someFuncition()
{
Serial.println(a);
Serial.printIn(b);
}

void setup (){
timer.serInteraval(1000L,someFunction);
}
void loop (){
timer.run();
}

You can’t pass parameters as part of the BlynkTimer/SimpleTimer call, but you can use global variables and set those values so that they are available within the function you are calling.

Pete.

where can I find an example of how to work with this, I cannot understand?

Just Google “variable scope in C++” and you’ll find lots of great tutorials on the subject.
This is not a Blynk or BlynkTimer or SimpleTimer issue, it is a fundamental concept of C++

Pete.

1 Like