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

@jojoboy I hope code below helps to your question:

‘’’ /* DEMO USING BLYNKTIMER CALLBACK WITH PARAMETERS*/

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID           "TMPxxxxxx"
#define BLYNK_TEMPLATE_NAME         "Device"
#define BLYNK_AUTH_TOKEN            "YourAuthToken"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char ssid[] = "XXXX";
char pass[] = "XXXXX";
BlynkTimer myTimer;
int myData;
int myTimerId;

void timerCallBack(void * data){
  Serial.print("Timer called.  This is the data: ");
  Serial.println(*(int*)data);     //As data is a generic pointer you must deference it using a pointer type according to data you expect. Or just use the pointer type according to your need.
}

void setup()
{
  Serial.begin(115200);
  myTimerId = myTimer.setInterval(1000L,timerCallBack,&myData);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}

void loop()
{
  Blynk.run();
  myTimer.run();
  myData = random(1,11);
}