Need help with my program

So i made this program for 2 leds to be turned on for 3 sec if you click the virtual button. But for some reason virtual button V1 doesent work.


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define led D1
#define led2 D2
int VirtualB = 0;
int VirtualB2 = 0;


char auth[] = "6e20fae28bc648c1a4abf8c15c3002e2";
char ssid[] = "GNX852DB0";
char pass[] = "VDTKC7PHMJFR";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(led,OUTPUT);
}

BLYNK_WRITE(V0)
{
  int VirtualB = param.asInt();
  Serial.print(VirtualB);
    
    if(VirtualB=1){
      digitalWrite(led,HIGH);
      delay(3000);
      digitalWrite(led,LOW);
    }
    else{
      digitalWrite(led,LOW);
    }
}

BLYNK_WRITE(V1)
{
  int VirtualB2 = param.asInt();
  Serial.print(VirtualB2);

    if(VirtualB2=1){
       digitalWrite(led2,HIGH);
      delay(3000);
      digitalWrite(led2,LOW);
    }
    else{
      digitalWrite(led2,LOW);
    }
}

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

You only have a signal equals symbol rather than two. The is setting VirtualB2 to 1, rather than testing its value.

However, your real problem is the blocking delay(3000) commands. You should be using a timeout timer instead.

Pete.

1 Like

Okey thank you very much forgot about double equals thing. Can I use the timer library from blynk?