Reset widget button

I have a very simple set-up with an Arduino Yun and 2 LED’s connected to 2 virtual pins. They are linked to 2 widget buttons in the blynk app and they will toggle ON and OFF with the widget buttons. What I want to accomplish is to light up LED 1 when widget button 1 is pressed. But when widget button 2 is pressed the LED 2 will momentarily light up to indicate that it was pressed and then both buttons reset to 0.

I can get the LED’s to turn off using a simple loop but the widget buttons are still in the ON possition when the LED has already reset. Can anyone help figure out how to reset the widget buttons?

Paste your code.

1 Like

As @Jamin says, we need to get some basic info to help you troubleshoot your issues :slight_smile:

Here is the code that I last tried…

/*

Blink

Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.

*/

// Pin 13 has an LED connected on most Arduino boards.

// Pin 11 has the LED on Teensy 2.0

// Pin 6 has the LED on Teensy++ 2.0

// Pin 13 has the LED on Teensy 3.0

// give it a name:

int led = 13;

int led1 = 7;

int led2 = 8;

//I had to modify the ‘‘include’’ lines below to not interact with my post

Bridge.h

YunClient.h

YunServer.h

BlynkSimpleYun.h

char auth[] = “blah blah blah”;

// the setup routine runs once when you press reset:

void setup() {

// initialize the digital pin as an output.

pinMode(led1, OUTPUT);

pinMode(led, OUTPUT);

pinMode(led2, OUTPUT);

Blynk.begin(auth);

Serial.begin(9600);

int tmft = 1;

}

// the loop routine runs over and over again forever:

void loop() {

  // Do your sketch stuff here



Blynk.run();

// while(led2 == true){

  if (led2 == true){

    delay(1000);

    Blynk.setProperty((led1, LOW), "offLabel", "false");

    Blynk.setProperty((led2, LOW), "offLabel", "false");

    Serial.println("stop button is engaged. Time to reset");

    

    Blynk.syncAll();

    }

   

  

  //}

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(led, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

}

This is not a very stable piece of code due to the delays you are using. You should use SimpleTimer and set flags to determine the status of the led’s and act accordingly. It’s bad practice, from a Blynk-perspective, to put anything else but Blynk.run() and timer.run() (for SimpleTimer) in the main loop.

It happens to make your code more readable too :slight_smile:

Thank you Lichtsignaal for such a quick response and I can tell you’re onto something. Would you mind showing me an example. I’m new to c code in general not to mention blynk’s syntax.

How can I modify what I have to accomplish the goal at hand?

Thank you in advanced for your input,

Steven

The SimpleTimer is very well documented over here:

http://playground.arduino.cc/Code/SimpleTimer

Please take a look at that. It is not the most difficult piece to comprehend, but if you have questions about, please let us know (I’d rather you figured it out a bit for yourself, it makes the learning a lot more effective and fun :wink: )