BLYNK
BLYNK.IO       📲 GETTING STARTED       đź“— DOCS       âť“HELP CENTER       👉 SKETCH BUILDER

Monostable output

Hello Everybody,
I’m testing an esp12e using blynk app.
I made n.4 buttons (n.2 push and n.2 switch) and work fine but I would like to set n.2 buttons as 3sec monostable activation:
When I press the blynk app button (push) I would like the Gp05 (d1) turns on for 2 seconds.
Sorry for the question but I really don’t understand what is the fast/better way to do that.
Thanks in advance.

Use a timeout timer…

Pete.

Thanks for your reply, but
… sorry for the question… what is the code to associate the timer to the output activation?

If output d0 is Hight use the timer and then go Low.

All the codes I found used a syntax with digital input…

I take it that you don’t have a lot of C++ programming experience?

Pete.

You’re right. sorry I am just moving my first steps…

Previoulsly I tried this code:

#define output0 16
#define output1 5

int output0_status = 0;
int output1_status = 0;


  Blynk.virtualWrite(V7, output0_status);
  Blynk.virtualWrite(V8, output1_status);
}

void setup()
{
    pinMode(output0, OUTPUT);
    digitalWrite(output0, LOW);
    pinMode(output1, OUTPUT);
    digitalWrite(output1, LOW);

}
void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer

      if(output0_status == 1){
    digitalWrite(output0, HIGH);
    delay(2000);}
    else { digitalWrite(output0, LOW); } //inserimento tolate

     if(output1_status == 1){
    digitalWrite(output1, HIGH);
    delay(2000);}
    else { digitalWrite(output1, LOW); } //inserimento notte
  
}

but didn’t work… So I asked here if someone can help me…

Please edit your post and add triple backticks at the beginning and end of your code, so that it displays correctly.
Triple backticks look like this:
```

Pete.

Here is another example of a "timed " reaction to an App button press…

Thanks,

I modified it as below and it works very fine. Thank you so much.

int latchButton1;
int latchFlag1;

int latchButton2;
int latchFlag2;

//===== Timeed latching button =====
BLYNK_WRITE(V7) {  // Button Widget set as switch
  latchButton1 = param.asInt();
  if (latchButton1 == 1 && latchFlag1 == 0) {
    latchFlag1 = 1;  // Keeps from allowing button press more then once while relay activated
    // ----- Start your timed thing here
    digitalWrite(D0, HIGH); // Activate digital pin
    // -----
    timer.setTimeout(2000L, []() {  // Timed Lambda Function - Latching Button release after 2 seconds
      // ----- Stop your timed thing here
      digitalWrite(D0, LOW); // Deactivate digital pin
      // -----
      Blynk.virtualWrite(V7, 0);  // Reset Latching Button to OFF
      latchFlag1 = 0;  // resets to allow next interaction
    });  // END Timer Function
  } else {
    if (latchButton1 == 0 && latchFlag1 == 1) {  // If you try to tun off the button before time is up
      Blynk.virtualWrite(V7, 1);  // Restore Latching Button ON until timer is finished
    }
  }
}



//===== Timeed latching button =====
BLYNK_WRITE(V8) {  // Button Widget set as switch
  latchButton2 = param.asInt();
  if (latchButton2 == 1 && latchFlag2 == 0) {
    latchFlag2 = 1;  // Keeps from allowing button press more then once while relay activated
    // ----- Start your timed thing here
    digitalWrite(D1, HIGH); // Activate digital pin
    // -----
    timer.setTimeout(2000L, []() {  // Timed Lambda Function - Latching Button release after 2 seconds
      // ----- Stop your timed thing here
      digitalWrite(D1, LOW); // Deactivate digital pin
      // -----
      Blynk.virtualWrite(V8, 0);  // Reset Latching Button to OFF
      latchFlag2 = 0;  // resets to allow next interaction
    });  // END Timer Function
  } else {
    if (latchButton2 == 0 && latchFlag2 == 1) {  // If you try to tun off the button before time is up
      Blynk.virtualWrite(V8, 1);  // Restore Latching Button ON until timer is finished
    }
  }
}