Segmented Switch Settings

Hi

Simple question. Is there a way I can set/change what OPTION is active in a Segmented Switch from the hardware side and see that reflected on the App. I tried : (in the case where Segmented Switch is V1 and I want to select OPTION 2

Blynk.virtualWrite(V1, 2);

Yes, the same way as a button, slider, etc… just as you show above, using a Blynk.virtualWrite(vPin, value) command, works for me on Android.

You will have to follow that up with a Blynk.syncVirtual(vPin) to "process " the command as if it was pressed on the App in order to trigger whatever Blynk function it controls. Again same as sketch controlled buttons, sliders and so on.

1 Like

thanks @Gunner yep got it working…was a silly bug on my end; need to sleep more :anguished:

Are you sure?

Because with this code where V0 is a 5 segmented switch and the sketch start with a

int inputSelected = 1;

if I click on the V50 widget (a simpe button) with this code

BLYNK_WRITE(V50) {
  if (param.asInt() == 1) { 
        if (inputSelected == 1) {   Blynk.virtualWrite(V0, 1); Blynk.syncVirtual(V0);}  
        if (inputSelected == 2) {   Blynk.virtualWrite(V0, 2); Blynk.syncVirtual(V0);}  
        if (inputSelected == 3) {   Blynk.virtualWrite(V0, 3); Blynk.syncVirtual(V0);} 
        if (inputSelected == 4) {   Blynk.virtualWrite(V0, 4); Blynk.syncVirtual(V0);} 
        if (inputSelected == 9) {   Blynk.virtualWrite(V0, 5); Blynk.syncVirtual(V0);}
  } 
} 

or like this:

BLYNK_WRITE(V50) {
  if (param.asInt() == 1) { 
        if (inputSelected == 1) {   Blynk.virtualWrite(V0, 1); }  
        if (inputSelected == 2) {   Blynk.virtualWrite(V0, 2); }  
        if (inputSelected == 3) {   Blynk.virtualWrite(V0, 3); } 
        if (inputSelected == 4) {   Blynk.virtualWrite(V0, 4); } 
        if (inputSelected == 9) {   Blynk.virtualWrite(V0, 5); }
        Blynk.syncVirtual(V0);
  }  
} 

the input ID 1 of the segmented switch is select correctly, but don’t trigger the command in the “case 1” of segmented switch. If I press manually on the app on ID 1, then trigger all ok.

1 Like