Invert Output

Is it possible to invert Button output. For example, now when I switch on a botton Arduino make it pin from LOW to HIGH level. Is it posible to invert it? When I switch on a botton then pin goes from HIGH to LOW?

Not possible via UI.

Nope, you have to remap it or use virtual pins with boolean logic.

Ok, thank you Lichtsignaal!

Did someone post an skerch example for that? Where to get it? Блин!!!

@zara

What’s the problem? Assign Virtual Pin to a Button Widget and then use the usual if statement:

BLYNK_WRITE(V1) //Button Widget is writing to pin V1
{
  if (param.asInt() ==  1){
    //set digital pin LOW
  } else if (param.asInt() ==  0) {
    //set digital pin HIGH
  }
}

Это я должен добавить в скетч и записать в свой esp8266? Через бинарник например?
Можно будет еще вопросик?

I don’t know which environment you use. If Arduino, then yes, this should be added to your sketch

The first idea that comes to my mind is just to invert the On/Off Labels… I’ve got a RBG Common Anode and this is what I do to turn the lights ON…

No, labels won’t work, sorry. :slight_smile: It’s just text

@Pavel I think what @psoro means is button on setting states OFF and vice versa. Sounds like a plan to me.

Im using arduino IDE and esp8266 drivers
i dont know where to put this code and
i dont know how to set gpio number to that virtual pin V1

i paste my sample here:

define BLYNK_PRINT Serial // Comment this out to disable prints and save space
include <ESP8266WiFi.h>
include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “49c30041acf845038f5617d8a4aef506”;

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, “mySSID”, “mypassword”, IPAddress(192,168,32,4));
}

void loop()
{
Blynk.run();
}
if i put it before “void loop()” i got “43:1: note: in expansion of macro ‘BLYNK_WRITE’
BLYNK_WRITE(V1) //Button Widget is writing to pin V1
^
exit status 1” ))))
“param was not declared in scope”

Yes @Costas, you are reading my mind!

@zara Have you tried looking at example sketches that come with the Blynk Library?

This one shows how to get data from the app. Please read the comments carefully.

I got you…
BLYNK_WRITE(V1) is a subroutine with (V1) variable

but there is still one question:
How to bind gpio2, for example, to V1?
I cant do if in UI!)))

BLYNK_WRITE(V1)
{
  if (param.asInt() == 0) {
    digitalWrite(2, HIGH);
  } else {
    digitalWrite(2, LOW);
  }
}

Got it! thankyou very mutch for your help

Pleace help me once again))))

How can i set default gpio state?
I add this code to sketch and got an invert output, but
BLYNK_WRITE(V1)
{
if (param.asInt() == 0) {
digitalWrite(2, HIGH);
} else {
digitalWrite(2, LOW);
}
}
It does not work, then there is no button with gpio2 binded
but if that button exist it sets default gpio2 state to HIGH and my relay turning on after powerlost and return

Here, I think this is everything you are wanting…

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "SID", "Pass");
  pinMode(2, OUTPUT);
  digitalWrite(2, LOW);  // Make this what ever you want you default value to be.
}

BLYNK_WRITE(V1)
{
  if (param.asInt() == 0) 
  {
    digitalWrite(2, HIGH);
  } 
else
  {
    digitalWrite(2, LOW);
  }
}

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

Could I request that this capability be added as an enhancement to the Button widget? Although it can be done using a virtual pin, I think it’s a common enough occurrence that it would be nice to be able to set inverted output in the widget itself. You could just add another switch for normal or inverted output, like the present one that allows selecting push or switch mode.

It would also be nice to have the same capability for the Timer widget.

All the other Controller widgets already allow you to invert the output by setting a “high to low” range instead of “low to high”

The problem with this is that the Button still “lights up” with the colour when it’s on, even if you’ve changed the label to “OFF”. It would be confusing if you had some active high buttons and some active low.

1 Like