Widget to just trigger some code in the device (and simple data entry widget)

What is the best widget to just trigger some code in the device.

Currently I’m using the button to run some code (e.g. resetting a bunch of internal - not blynk - variables) and then within the BLYNK_WRITE() I’m resetting the button state back to 0/off.

Can’t get much simpler than the mighty Button Widget :wink:

BLYNK_WRITE(vPin) {  // Button Widget
  int Button = param.asInt();
  if (Button == 1) {
    // Do all your stuffs here
    // Or call a function that does all your stuffs there
  } else {
    // Optional - Do something else here when button is turned back off.
  }
}

Might be in danger of a misunderstanding here and invoke the @Gunner sharp wit.

I just want to do one thing not 2 things. It is not button state dependant.

I just want to kick something off once.

Therefore to use the button I need to return it to the off state once I have triggered the code I want. This is OK within the blynk_write but it would be easier if we just had a trigger button that had no state

Hi @Gunner and @Dmitriy. Any further thoughts on the best widget other than the button for this requirement? Or if not then perhaps is a thought for a new widget?.

Also as I’m asking what is the best way to send a single string value to the device from the phone other than the terminal/console what is an over kill and expensive. Sort of a simple string entry field - bit like an editable label.

I think I understand what you want… perhaps a “One Hit Widget”?

I’m just saying there is no need for another widget to do it… nor honestly can I think of a single reason (is that witty enough ;P) to ever have such a limited widget, when we can already use what we have, to do whatever we want, however we want it.

Code to allow one action, on push not release, and only the one time like this:

int FLAG = 0;

BLYNK_WRITE(vPin) {  // Button Widget set to PUSH
  if (param.asInt() == 1 && FLAG == 0) { 
    FLAG = 1;
    // Do your stuffs here once and only once
   }
}

Or if you do want the action to be repeatable, but again only on push, not release

BLYNK_WRITE(vPin) {  // Button Widget set to PUSH
  if (param.asInt() == 1) { 
    // Do your stuffs here once button pushed
   }
}

Now if you are asking for something that does that without any code… well, I can’t see that happening either… no applicable use case comes to mind. But hey, you never know :wink:

Please feel free to correct me if i am still misunderstanding… worst case is I hit the keys harder!! on my rebuttal :smiley:

PS - I missed this part… The default setting on a Button is PUSH mode, which means it will automatically return to OFF when released.

As for this… I think something like a simple data entry widget has been requested and being worked on… or at least on the ToDo list.

But if not, then I agree wholeheartedly… Basically I picture something like a one way terminal that takes up smaller space. Perhaps like a Display Widget size, that shows the data being entered until the Enter/Return key is pressed… then it sends the string.