Docs

Menu

The Menu widget shows a list and sends the index of the option you pick.

Use it for: a mode selector, a preset, a fan speed named Low, Medium and High, a recipe to run.

SettingWhat it does
Pinthe virtual pin your code reads
Itemsthe options, in order

Open these from the canvas: tap Edit, then long press the widget and choose Configure.

The first item sends 1, the second 2, and so on. Indexes start at one, not zero.

Example

Three modes on V15.

menu.ino
#include <PlynxSimpleEsp32.h>

#define FAN_PIN 27

PLYNX_WRITE(V15)
{
  switch (param.asInt()) {
    case 1:                           // Off
      ledcWrite(FAN_PIN, 0);
      break;
    case 2:                           // Low
      ledcWrite(FAN_PIN, 120);
      break;
    case 3:                           // High
      ledcWrite(FAN_PIN, 255);
      break;
  }
}

void setup()
{
  Serial.begin(115200);
  ledcAttach(FAN_PIN, 25000, 8);

  // Auto setup: WiFi and the Plynx token are configured from the app.
  //
  // To provide them directly in the sketch instead, use:
  //   Plynx.begin(auth, ssid, pass);
  Plynx.begin();
}

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

Keep the order of the items and the order of the cases together. Adding an option in the middle of the list shifts every index after it, and the sketch starts running the wrong branch.

Troubleshooting

ProblemCheck
Wrong mode runsan item was added or moved; the indexes shifted
Nothing happens on the first itemindexes start at 1, so case 0 never runs
Menu shows old optionsupdate the widget settings and reopen the project

Next