Passing Param

Hej,

so i would like to pass param to a function.

my goal is to have multiple blynk_writes(Vx) and only 1 function. I am using Time Input Widget. I am not sure what kind of type is param.

Something like this:

BLYNK_WRITE(V1) {
  blynkTimeInput(param);
}

BLYNK_WRITE(V2) {
  blynkTimeInput(param);
}

BLYNK_WRITE(V3) {
  blynkTimeInput(param);
}

void blynkTimeInput(type??? param) {
TimeInputParam t(param);

//do something
}

Your code is incorrect

Example from http://examples.blynk.cc shows:

BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("V1 Slider value is: ");
  Serial.println(pinValue);
}

then you collect all `pinValues’ you need and pass them to function. Of course they all should be global variables

void blynkTimeInput(pinValue1, pinValue2, pinValue3) 
{
//do something
}

my code works if i use like this:

BLYNK_WRITE(V1) {
TimeInputParam t(param);

//do something
long startTimeInSecs = param[0].asLong();
 long endTimeInSecs = param[1].asLong(); 
}

but now i wont to move it to function like in my first post …

so i want to pass whole “param” not a single pinValues…

[AdvancedTimeInput](https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=Widgets%2FTimeInput%2FAdvancedTimeInput)

ok i have found a solution for my problem:

BLYNK_WRITE(V1) {
  blynkTimeInput(param);
}

void blynkTimeInput(const BlynkParam& param) {

  TimeInputParam t(param);
  //do something
}
>    BLYNK_WRITE(V1) {
> TimeInputParam t(param);

> //do something
> long startTimeInSecs = param[0].asLong();
> long endTimeInSecs = param[1].asLong(); 
> }

but now i wont to move it to function like in my first post …

so i want to pass whole “param” not a single pinValues…

AdvancedTimeInput

ok i have found a solution for my problem:

> BLYNK_WRITE(V1) {
> blynkTimeInput(param);
> }

> void blynkTimeInput(const BlynkParam& param) {

> TimeInputParam t(param);
> //do something
> }

Try putting your code like this, you can do this by using , its easier on the eyes :wink:

I fixed his posts with the recommended three backticks fore and aft.

It seems the OP resolved whatever he was looking to accomplish, so marking this solved.

1 Like

I was waiting for that picture to pop up :stuck_out_tongue:

1 Like