Hi, I’m using Blynk 2.0 and NodeMcu to control a relay with a led strip connected, but I can’t invert the status of the button (V1). Very simple and fast thing in the Blynk 1.0 version where you can decide the value of the inverted button, that is 1 off 0 on.
#define pulsante 5
BLYNK_WRITE(V1) { digitalWrite(pulsante, param.asInt());}
int stato = 0 ;
void Pulsanti() {
if (digitalRead(D1) == LOW ){
Blynk.virtualWrite(V1, LOW);
}
if (digitalRead(D1) == HIGH ){
Blynk.virtualWrite(V1, HIGH);
}
}
@seby please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Here is the complete code where with theV1 button the led strip connected to the relay lights up, instead through the V2 the brightness of the strip through PWM and transistor TIP 41C NPN Everything works perfectly through Blynk 1.0
The stuff that yoire doing with writing the V1 value to GPIO5 (Pin D1 on the NodeMCU) is very clunky.
First of all, mixing GPIO numbers and D numbers makes the code very difficult to follow.
It also seems to be a work-around for simply using global variables or passing parameters to a function, but if you’re happy and it works for you then that’s all that matters.