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

Use BLYNK_WRITE(V200)

Dear friends,
I need your help. I want to use virtual V200 pin, V201, V202, but they don’t work, how do they work? Thank you friends. best wishes to you.


BLYNK_WRITE(V200)
{
  if (param.asInt() == 0)
  {
  Serial.println("1111");
  }
  if (param.asInt() == 1)
  {
   Serial.println("2222");
  }

Try BLYNK_WRITE(200)

It still doesn’t work

Note: For virtual pins with numbers > 127, please use BLYNK_READ_DEFAULT() API

BLYNK_WRITE_DEFAULT()

I dont know hou to use it

I got it !
Your are using V200 as a virtual button
In that case you have to use :

BLYNK_WRITE_DEFAULT()
{
  int pin = 200;      // Which exactly pin is handled?
  int value = param.asInt();  // Use param as usual.
}

BLYNK_WRITE(200,“abc”) is required to write to a label widget
@PeteKnight, tell me if I’m wrong :blush:

It still doesn’t work

I’ve never has to use BLYNK_WRITE_DEFAULT(), but according to he who knows everything, its not quite the way you’ve described:

In the example @GunnerTechTools gives, it seems that request.pin returns the pin that triggered the BLYNK_WRITE_DEFAULT() callback:

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
  }
}

so if you had different code that ran for V200, V201, V202 then you’d need to use a series of ‘if’ statements, or a Select Case statement.

Pete.

it is what I said :rofl:

BLYNK_WRITE_DEFAULT()
{
  int pin = 200;      // Which exactly pin is handled?
  int value = param.asInt();  // Use param as usual.
}

But @GunnerTechTools s using request.pin to discover which pin triggered the callback. He happens to be storing it in an integer called pin, but it seems to me that it’s the request.pin keyword that’s the critical part.
As I said, I’ve never used it, and not tested either bits of code so I could be wrong.

Pete.

Oh yes ! I’m wrong !
I need to test myself to understand how request.pin works !

:innocent:

2 Likes

Dear friends,

BLYNK_WRITE(V200)
{
  if (param.asInt() == 0)
  {
  Serial.println("1111");
  }
  if (param.asInt() == 1)
  {
   Serial.println("2222");
  }

I need your help. I want to use virtual V200 pin,but it does’t work,how does it work?
Thank you my friends.
@PeteKnight@ Dmitriy@ wanek @ Pavel GunnerTechTools

Please don’t attempt to tag multiple Blynk staff members in your posts on this forum. They are very busy, and monitor the forum when they have the opportunity, but they won’t get involved in answering questions like this, especially when the answer has already been provided.
Tagging people in this way will get your membership of this forum suspended.

We’ve already shown you that the solution is to use BLYNK_WRITE_DEFAULT() instead of BLYNK_WRITE(V200), and that request.pin will return the number of the pin that triggered the BLYNK_WRITE_DEFAULT callback.

Pete.

1 Like

As @PeteKnight Pete has already said, the answer is right there.

And because I’m feeling generous, I even wrote a little code for you (you can then add to this for other Vpins:

BLYNK_WRITE_DEFAULT() {
  switch (request.pin)
  {
    case 200:
      if (param.asInt() == 1)
      {
        // do something
      } else {
        // do something else
      }
      break;

    case 201:
      if (param.asInt() == 1)
      {
        // do something
      } else {
        // do something else
      }
      break;
  
    case 202:
      if (param.asInt() == 1)
      {
        // do something
      } else {
        // do something else
      }
      break;
  }
}
3 Likes

Sorry, it won’t be in the future, it works, thank you very much and Blynk_Coeur for your help, and thank you for the blynk staff members who are silently paying.

1 Like