Docs

Segmented Control

The Segmented Control shows every option side by side and sends the index of the one you tap.

Use it instead of a Menu when there are two to four options and you want them all visible: Off, Auto, On.

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

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

The first segment sends 1, the second 2, and so on, the same as the Menu.

Example

Heating mode on V16.

segmented-control.ino
#include <PlynxSimpleEsp32.h>

#define HEATER_PIN 25

int mode = 1;                         // 1 off, 2 auto, 3 on

PLYNX_WRITE(V16)
{
  mode = param.asInt();
}

void setup()
{
  Serial.begin(115200);
  pinMode(HEATER_PIN, OUTPUT);

  // 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();

  float room = analogRead(34) * (3.3 / 4095.0) * 100.0;

  bool on = (mode == 3) || (mode == 2 && room < 20.0);
  digitalWrite(HEATER_PIN, on ? HIGH : LOW);
}

Store the choice and act on it in loop(). A mode is a state, not an action, so the handler only records it.

Troubleshooting

ProblemCheck
Wrong branch runssegments were reordered; the indexes shifted
Selection resets on rebootadd Plynx.syncVirtual(V16) inside PLYNX_CONNECTED()
Too many options to fituse a Menu instead

Next