Blynk_write_default() & blynk_read_default()

today I’m trying to understand the use of these two calls … but I really can not, the description is too synthetic … can someone help me to understand adding an explanation or better some examples? Thank you very much

Hello.

They are basically a way of writing code that is independent of pre-selected vPins… and a feature that I have never really bothered to use, so not sure of its benefit with a project that is generally mapped out.

But instead of setting a Button widget with V1 and then writing vPin specific code like…

BLYNK_WRITE(V1) {
  if (param.asInt() == 1) {
    Serial.println("Button is pressed");
  } else {
    // Do something, or nothing, when button is OFF
  }
}

You can write this… that will work with a button set to any vPin that is not already assigned in code.

BLYNK_WRITE_DEFAULT() {
  int pin = request.pin; // determines what vPin is triggering this response
  if (param.asInt() == 1) {
   Serial.print("Button on Virtual Pin ");
   Serial.print(pin);  // Display the number of the vPin
   Serial.println(" is pressed");
  } else {
    // Do something, or nothing, when button is OFF
  }
}

And the difference between the ‘read’ vs ‘write’ is the same as described here

NOTE I think this type of function can only be used ONCE in a sketch… as I get compiling errors if I try to run it multiple times.

1 Like