Disable Button Function Until Another Button Function Activated

I need help finding a way to disabling the ability to activate V10 after it is initially activated, until V11 is activated. This way it is not activated twice and can only be activated from its original position. I’m creating a gas valve that will open the valve and start igniter with one button, and then close the gas valve with another button. Thank you for your assistance as I have tried to find information on this for some time.



#define BLYNK_PRINT Serial
#define PIN 14
#define PIN 12
#define PIN 13

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


char auth[] = "Auth Code";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "LOGIN";
char pass[] = "PASS";

const int valveOpen = 14;
const int igniterOn = 12;
const int valveClosed = 13;

BlynkTimer timer;
void STOP_Motor()
{
  digitalWrite(valveClosed, LOW);
  digitalWrite(valveOpen, LOW);
  digitalWrite(igniterOn, LOW);

}

//DISABLE SECOND BUTTON PRESS UNTIL BUTTON2 (EXTINGUISH) IS ACTIVATED

BLYNK_WRITE(V10) //Button Widget is writing to pin V10
//Opens valve and ignites gas if V10 pressed, disengages at 2.5s
{

  int pinData = param.asInt(); 

  if (pinData == 1) 
  {
   digitalWrite(valveOpen, HIGH);
   digitalWrite(igniterOn, HIGH); //Igniter turns on

   timer.setTimeout(2500L, STOP_Motor); // Stops motor at 2.5seconds

  }
  
}

BLYNK_WRITE(V11) //Button Widget closes the valve
//Activates motor for 2.5 seconds and closes valve
{

  int pinData = param.asInt(); 

  if (pinData == 1) 
  {
   digitalWrite(valveClosed, HIGH);


   timer.setTimeout(2500L, STOP_Motor);

  }
  
}


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

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  pinMode(14, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  digitalWrite(14,LOW);
  digitalWrite(12,LOW);
  digitalWrite(13,LOW);
  


}

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

  
}


You don’t “disable” the function itself… but you can add in a flag check to see if the other function has completed or not.

 if (pinData == 1 && some flag check is correct )  // set the flag in whatever other function you need to be completed first.
1 Like

Perfect. I got it to work. Thank you for your assistance!! Now I just have to figure out how to save the flag and not have it reset when the board accidently disconnects.

Below is the updated code for anyone who might be interested:

#define BLYNK_PRINT Serial
#define PIN 14
#define PIN 12
#define PIN 13

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

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "LOGIN";
char pass[] = "PASS";

const int valveOpen = 14;
const int igniterOn = 12;
const int valveClosed = 13;
int motorInitiated = 0;
BlynkTimer timer;
void STOP_Motor()
{
  digitalWrite(valveClosed, LOW);
  digitalWrite(valveOpen, LOW);
  digitalWrite(igniterOn, LOW);

}



//DISABLE SECOND BUTTON PRESS UNTIL BUTTON2 (EXTINGUISH) IS ACTIVATED

BLYNK_WRITE(V10) //Button Widget is writing to pin V10
//Opens valve and ignites gas if V10 pressed, disengages at 2.5s
{

  int pinData = param.asInt(); 

  if (pinData == 1 && motorInitiated == 0) 
  { 
   digitalWrite(valveOpen, HIGH);
   digitalWrite(igniterOn, HIGH); //Igniter turns on

   timer.setTimeout(2500L, STOP_Motor); // Stops motor at 2.5seconds
   motorInitiated++;  // Sets motor Initiated to 1
  }
  
  
}

BLYNK_WRITE(V11) //Button Widget closes the valve
//Activates motor for 2.5 seconds and closes valve
{

  int pinData = param.asInt(); 

  if (pinData == 1) 
  {
   digitalWrite(valveClosed, HIGH);


   timer.setTimeout(2500L, STOP_Motor);
   motorInitiated = 0;
  }
  
}


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

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  pinMode(14, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  digitalWrite(14,LOW);
  digitalWrite(12,LOW);
  digitalWrite(13,LOW);
  


}

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

  
}

Save it to a virtual pin.

Blynk.virtualWrite(vPin, value)

and use the sync function when restarting

BLYNK_CONNECTED() {
  // Request the latest state from the server
  Blynk.syncVirtual(vPin);
}

More specifically:

BLYNK_WRITE(V10) //Button Widget is writing to pin V10
//Opens valve and ignites gas if V10 pressed, disengages at 2.5s
{

  int pinData = param.asInt(); 

  if (pinData == 1 && motorInitiated == 0) 
  { 
   digitalWrite(valveOpen, HIGH);
   digitalWrite(igniterOn, HIGH); //Igniter turns on

   motorInitiated++;  // Sets motor Initiated to 1
   Blynk.virtualWrite(V20, motorInitiated); //write value to server

   timer.setTimeout(2500L, STOP_Motor); // Stops motor at 2.5seconds
   
  }
  
  
}

BLYNK_WRITE(V11) //Button Widget closes the valve
//Activates motor for 2.5 seconds and closes valve
{

  int pinData = param.asInt(); 

  if (pinData == 1) 
  {
   digitalWrite(valveClosed, HIGH);

    motorInitiated = 0;
    Blynk.virtualWrite(V20, motorInitiated); //write value to server

   timer.setTimeout(2500L, STOP_Motor);
  
  }
  
}

BLYNK_WRITE(V20) //Refresh motorInitated from server

{

  motorInitiated = param.asInt(); 
  
}

BLYNK_CONNECTED() {
  // Request the latest state from the server
  Blynk.syncVirtual(V20);
}

Although untested.

1 Like

Thank you very much for your help! It works perfectly! :grin: You guys saved me so much time you have no idea.