[SOLVED] Using V1 to lock V0 (both outputs)

Hi,

Just a thought experiment here, but is it possible for one virtual pin value to prevent the app changing the value of another virtual pin?

I ask mostly out of curiosity, but it would be interesting to use in my project. There’s a slider controlling V0, which controls the speed of a fan. Could I then use V1 in a menu widget which can lock the value of V0 (and therefore the fan speed) to specific values || allow full slider use? 100% PWM, 50%, off, custom etc etc.

I assume it would be an if(V1value)-else statement for the Arduino to ignore additional changes to V0 unless allowed by the value of V1, but can I lock the GUI by virtualWriting to V0 even though it’s being used for an app output?

Still waiting for a connection to a Blynk server (network firewalls and ports etc.) so I can’t currently road-test the idea, but could that work?

Hi.

Yes.

bool isLocked = false;

BLYNK_WRITE(V0) {
   if (isLocked) {
       //do no allow any change...
   } else {
       //some regular logic
  }
}

BLYNK_WRITE(V1) {
    isLocked = true;
}

Thank you. Will that also lock the V0 slider or will it just mean changing the slider position has no effect?

Correct.

Okay, I see. So the Arduino hunch was right, thank you.

My question was mostly whether there was a way I could lock the slider from the perspective of the app user, or at least have it re-update back into the pre-set position. Am I right in thinking that Blynk.virtualWrite(pin, value) won’t work for a virtual pin set up for sending data from app to microcontroller? The information would be gong the wrong way in my head.

No. However this feature is in todo list.

Okey doke, good to know. Good luck, and thank you for your time :slight_smile:

1 Like

Until then you could do something like this

bool isLocked = false;
int previousValue = 0; // some default value 

BLYNK_WRITE(V0) {
   if (isLocked) {
       //do no allow any change...
      Blynk.virtualWrite(V0, previousValue);
   } else {
       previousValue = param.asInt();
       //some regular logic
  }
}

BLYNK_WRITE(V1) {
    isLocked = true;
}

This should reset your slider if it’s " locked "

1 Like

That works a treat, thank you! I need to move the slider before it resets, but otherwise this works well.

Good to know, yea I imagined that would be the case on startup.
You could play with blynk sync functions to avoid that issue, didn’t have any of the code in my head for it :slight_smile: