Can't print message at terminal, if the condition is met

Hi.
I have a simple program, there are 2 buttons, which are assigned to virtual pin 127 and 128.
If the 1st button is pressed, the flag (K) is increasing by 1, if the 2nd button is pressed, same story with flag (L).
If “K” and “L” =1, then I have to receive the message at terminal: “Working”.
But unfortunatelly, it isn’t working.
Please advice.

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "1TP1";
char pass[] = "";
int K=0; // флаг
int L=0; // флаг 2


BLYNK_WRITE(V127)                       // обработчик  кнопки калитка
{
  int pinData = param.asInt();
  if(pinData==1){
      K=1+K;                            // просто устанавливаю флаг по клику кнопки    , причем флажок устанавливается в момент нажатия кнопки 
     }  
}


BLYNK_WRITE(V128)                       // обработчик  кнопки калитка
{
  int pinData = param.asInt();
  if(pinData==1){
      L=1+L;                            // просто устанавливаю флаг по клику кнопки    , причем флажок устанавливается в момент нажатия кнопки 
     }  
}




// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);

  
void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.println(K);
  terminal.println(L);
  terminal.flush();
}

void loop()
{

 if(K==1 && L==1){
  terminal.println(K);
  terminal.println(L);
  terminal.println("Working") ;
  terminal.flush();
  
  
}
  Blynk.run();
}

V128? is not one of the usual Virtual Pins. Until recently V127 was the max. I know they are allowed, now, sorta, but I think they need to be handled differently.

Could it be an issue in your case?

Yep, that is it… Any vPin after 127 will not work in a normal BLYNK_WRITE() function, you need to use the BLYNK_WRITE_DEFAULT() function instead. Like this…

BLYNK_WRITE_DEFAULT() {  // For use with vPin 128-256
  if (request.pin == 128) {
    int pinData = param.asInt();  // Set the virtual button flag
    if (pinData == 1) {
      L = 1 + L;
    }
  }
}

But, that function can only be used once or else compilation issues…

So if you want to use more you need to use additional if() else logic like this…

BLYNK_WRITE_DEFAULT() {   // For use with vPin 128-256
  if (request.pin == 128) {
    // Do V128 stuff
  } else if (request.pin == 129) {
    // Do V129 stuff
  } else if (request.pin == 130) {
    // Do V130 stuff
  }  //... and so on...
}
1 Like

Yes, U were right, thanks for your help