Help with virtual pin

hello,
i want to blink a led with virtual pin, but it does not work and this is my code

#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>


char auth[] = "3b43306524974feda9047xxxxxxxx";

void setup()
{
 
  DebugSerial.begin(9600);
  pinMode(2, OUTPUT);


  Serial.begin(9600);
  Blynk.begin(auth, Serial);
 
}
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); 
  if(pinValue==1){
    digitalWrite(2, HIGH);}
    else{
      digitalWrite(2, LOW);
      }
}


void loop()
{
  Blynk.run();
}

@alyaa_sheir

Define: [quote=“alyaa_sheir, post:1, topic:10375”]
blink a led with virtual pin
[/quote]

i.e. Blink when holding button; Blink when toggling button (ON); Blink when giving the button a nasty look; Don’t ask questions, JUST BLINK DARN IT… etc.

EDIT: OK, normally the idea is to help you to learn how to get these answers yourself, not do it for you… so I will start off with the obligatory RTM - http://docs.blynk.cc/#blynk-firmware-virtual-pins-control, but I understand how lacking of clear examples those DOCs seem to be…

…And I was bored :smile:

So here is how I just learned to make a “blink LED while button held down” function. Probably much better ways, but hey, I’m just learning too :wink: Feel free to use this and tweek it to your purpose.

BLYNK_WRITE(V1) // Run this funtion when V1 button presed.
{
  int pinValue = param.asInt();  // Get status of V1.
  if (pinValue == 1) {  // If status of V1 is 1 then do stuff in if().
    digitalWrite(2, HIGH); // Turn on LED.
    delay(20); // Wait 10 millis but remember you are holding up the sketch.
    digitalWrite(2, LOW);  // Turn off LED.
    Blynk.run(); // Return to rest of Blynk operations, in-between waiting for this loop to repeat or quit.
    int pinValue = 0;  // Set V1 status to 0 to quit... unless button is still pushed (as per below)
    Blynk.syncVirtual(V1); // ...Then force BLYNK_WRITE(V1) function check V1 button status to determine if repeating or quitting loop.
  }
}

thanks alot it did work i think the problem was with the delay

The key was actually: Blynk.syncVirtual(V1);

Thus getting the function loop to re-check the button action, while still running the loop. Otherwise one had to keep pressing the button to get a short blink… or (depending on method of loop) even getting stuck in the function loop until reset.