Virtual trigger calls the function twice

For my project i have used virtual pins to call the function
But instead of calling the the function just one it is recalled two time in my particle photon
For example when i try to blink an led once in the function, called through the virtual pin. it completes the cycle once and is again called. So basically the led blinks twice.

Help!!!

Are you using a button widget and is it PUSH or SWITCH mode?
You should be able to code a single blink.

i am using push mode for the blynk ]

PUSH means go high and then go low, perhaps this is why you are seeing 2 entries.

Can you post an extract of your Blinking code.

this is the code that i used in project as simple tigger to give led a signal.

// This #include statement was automatically added by the Particle IDE.
#include “Adafruit_DHT/Adafruit_DHT.h”

// This #include statement was automatically added by the Particle IDE.
#include “blynk/blynk.h”
#define DHTPIN 5
#define DHTTYPE DHT11

// Variables
int temperature;
int humidity;

// Pins

// DHT sensor
DHT dht(DHTPIN, DHTTYPE);

char auth[]=
void setup() {
dht.begin();
pinMode(D0, OUTPUT);

Blynk.begin(auth);
}

void loop() {
Blynk.run();

 temperature = dht.getTempCelcius();

// Humidity measurement
humidity = dht.getHumidity();

int temp= temperature;
Blynk.virtualWrite(V1, temp);
delay(500);
int hum = humidity;
Blynk.virtualWrite(V2, hum);
delay(500);

}
BLYNK_WRITE(V0)
{
digitalWrite(D0, HIGH);
delay(1000);
digitalWrite(D0, LOW);
delay(1000);
digitalWrite(D0, HIGH);
delay(1000);
digitalWrite(D0, LOW);

}

So many problems. You can’t use Arduino sketches without updating them for use with Blynk.

You don’t post code like that on any forum

Don’t publish your security credentials on an open forum.

Study all the docs and good selection of the examples.

oo the code run fine but the last, the last function is some how running two times.
every time i push the button

it is not running fine, just trust me on that one.

delay() is “not allowed” with Blynk.

The developers went to great time and effort to write dozens of sketches for beginners to use their system. At least one shows you how to correctly blink LEDs with Blynk.

ooo ok. didnt know about the delay sorry really new to these stuff
could u suggest any one example for the trigger or blink led
would be a great help

No I’m going let you find them. It’s not difficult.

You should add to the code block the if statement with asInt() method parameter to prevent double (twice) calling. It’s cuz, you receive data from Virtual Pin and here is need to convert to integer or receive like integer variable. For example, controlling physical GPIO18 via V3 virtual pin:

#define GPIO18 18

BLYNK_WRITE(V3)
{
  if (param.asInt()) {
    digitalWrite(GPIO18, LOW);
    // delay(1000);    ==> millis()
    digitalWrite(GPIO18, HIGH);
  }
}
1 Like

@AVicenNA please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

Hopefully, after 4 years the OP has either figured this out or found a workaround.

Pete.

1 Like