[SOLVED] Virtual Pin indirect addressing (Using variables instead)

Hello,

Can I address virtual pins indirectly i.e instead of writing V1,V2,V3 etc I would write something like V[i] where i can be any int from 0 to the maximum number of virtual pins?
thank you

Julia

Every virtual pin is defined as a number
V0 = 0
V1 = 1
V2 = 2


And so on.
So you can simply use numbers instead

@papex Hello, and yes you can treat the Vpin as a variable instead… and as @Fettkeewl says, you don’t really need the V anyhow. In my example, I used “Vcount”, but it could have just as easily been “Fred”.

BLYNK_WRITE(49) {  // Button in momentary mode
  if (param.asInt() == 1) {
    for (Vcount = 50; Vcount <= 55; Vcount++) {  // generate 6 Vpin numbers (V50-V55) for the displays
      Blynk.virtualWrite(Vcount, millis());  // Print out the current millis to a group of 6 displays
      delay(1);
    }
  }
}

Hello. Yes. And here is also example - https://github.com/blynkkk/blynk-library/blob/master/examples/More/PrintAllVirtual/PrintAllVirtual.ino

thank you all for the responses.
It seems however that if I put a variable in BLYNK_WRITE it does not work.
I have int v=5;
BLYNK_WRITE(v) does not work but BLYNK_WRITE(5) works.
is the correct behaviour?

I found the solution by using Dmitriy’s example and testing for requestpin=v and put my handler there.
Thank you all
Julia

@papex Thanks for that extra insight… I just couldn’t get my head around the GitHub example, but now I have it :smiley:

Here is my modified example for others to see how that works.

BLYNK_WRITE_DEFAULT() {  // called when any unhandled widget is triggered.
  if (request.pin == 49 and param.asInt() == 1) {  // Checks if the triggered widget is set for V49 and it's state is HIGH.
    for (Vcount = 50; Vcount <= 55; Vcount++) {  // generate 6 Vpin numbers for the displays.
      Blynk.virtualWrite(Vcount, millis());  // Print out the current millis a group of 6 displays.
      delay(1);
    }
  }
}
1 Like