(SOLVED) Control Menu widget from hardware

Hello.
Shortly… Can I control menu widget (cases) from hardware?

Something like this:

BLYNK_WRITE(V1) 
 {switch(param.asInt())
  {case 1: { kjlkjlkjlkjlkj=1; break;}
    case 2: { dfkdflgjdf=234234; break;}
}


if (glfkgjlfjg==0)
{Blynk.virtualWrite (V1 , case 2);}

if (AAAAAA==aa)
{Blynk.virtualWrite (V1 , case 1);}

Have you checked the documents? It appears that is already available.

http://docs.blynk.cc/#widgets-interface-menu

I read this. But not quite clear.

How can I write the code, to set menu widget in state (case1)?

like this?
Blynk.setProperty(V12, case 1);

or this?
Blynk.setProperty(V12, “Menu item 1”);

Using Case with the Menu Widget is for reading from the menu selection (on the app) and enacting the action in hardware.

if you want to change the menu text (on the app ) from the hardware… keep reading further down on the Blynk.setProperty() description in the Docs:

Menu
labels is list of strings for Menu widget selections;

Blynk.setProperty(V0, "labels", "label 1", "label 2", "label 3");

But there is no reason to have the hardware tell the app which choice to pick, based on something, when you can code the same action directly in the hardware, based on that same something.

You can just set labels but not selected item.

@Dmitriy Ah…

I was going to suggest something like this… but I guess that will not work for the Menu Widget?

Blynk.virtualWrite(V0, 2); // Choose case2
Blynk.syncVirtual(V0); 
2 Likes

yeah) dont’work)

ok. To change the value of the menu widget like as a button widget (ON OFF with virtual write), I need to change label. Right? of course the same action directly in the hardvare I write separately.

1 Like

My understanding of the Menu Widget is that it is App side input only (aside from setting names).

Gunner
> But there is no reason to have the hardware tell the app which choice to pick, based on something, when you can code the same action directly in the hardware, based on that same something.>

A reason should be to re-synchro the state of the widget app-side with the state of the hardware-side after a disconnect.
Pratically, sometimes I send command but the app is offline and I have a mismatch between two sides…

To avoid this, it should be a nice improvment if the app should simply block changing display of actions when the link with hardware is lost… Or even better, check if the command has well been received on the hardware-side (acknowledge process).

It works! great. Exactly that I need. The state of menu changed according sending digit.
Thanks for all. Especially to Gunner for idea)

2 Likes