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

How to use variables to read virtual pin status dynamically in BLYNK_WRITE?

Hi community,

I want to read status of 8 virtual pins by dynamically assign virtual pin parameter to BLYNK_WRITE. Unfortunately following code is not working:

BLYNK_WRITE(pin);
   { 
   int status = param.asInt();
   call_a_function(status);
   }

void loop() 
{
int i = 0;
while (i <=7)
{
    String pin = "V" + String(i);
    Blynk.run();
    i++;
}
}

Thanks!

Like this:

BLYNK_WRITE_DEFAULT()
{
  int widget_pin = request.pin;      // Which virtual pin triggered this BLYNK_WRITE_DEFAULT callback?
  int widget_value = param.asInt();  // Get the value from the virtual pin
}

Pete.

Hi Pete,
thanks for quick reply. This works like a charm, thanks!
The docs now make sense for me and I hope it’ll provide more cool stuff for me :slight_smile:

1 Like