Segmented Switch

A row of two to five options, one selected — like a tab bar. Mode: Off / Auto / Manual. Speed: Low / Mid / High. It says which one at a glance, and the device gets a number.
What it does
Each segment carries a label you see and a value the device receives. Tapping a segment writes its value to the signal — 0, 1, 2 by default, or whatever you set. Exactly one segment is selected at a time; the app shows which, and the device knows it the instant it changes.
When to use it
- A mode — Off / Auto / Manual for a heater, an irrigation, a light. The device switches its own logic on the index.
- A preset — Low / Mid / High mapped to three PWM duty cycles.
- A source — A / B / C: which sensor, which channel, which tank.
Set it up
- Place it — In edit mode, tap + at the bottom of the dashboard and choose Segmented Switch under Controllers. It lands on the grid with three segments.
- Wire it to a signal — Tap the widget, open the Data tab, tap + Add a target and pick an Integer signal on your device.
- Name the segments — In the same tab, under Segments, give each segment its label — Off, Auto, Manual — and the value it sends. Tap + Add a segment for a fourth or a fifth, or the bin to remove one; two is the minimum.
- Try it — Close the settings, tap ▶, and tap a segment: the device receives its value.
Settings
Tap the widget in edit mode: the sheet opens with a live preview at the top, then two tabs — Data for what it reads or writes, Appearance for how it looks.
Data — what it writes
Targets
| Setting | Type | Default | What it controls |
|---|---|---|---|
| Targets | list of signals | empty — No target yet. The tap goes nowhere. | The signal the widget writes to. Accepts an Integer signal only — one whole number per segment. The picker lists nothing else. + Add a target for a second device: every target gets the value. |
Segments
| Setting | Type | Default | What it controls |
|---|---|---|---|
| Label | text | Opt1, Opt2, Op3 | The text on the segment. |
| Sends | integer | 0, 1, 2 |
The value written when the segment is tapped. Use the numbers your sketch already uses. |
| + Add a segment / 🗑 | buttons | 3 segments | Add a segment (up to 5) or remove one (down to 2). |

Appearance — how it looks
Title
| Setting | Type | Default | What it controls |
|---|---|---|---|
| Title text | text | empty | A title above the widget. Empty means no title. |
| Alignment | Left / Center / Right | Center | Where the title sits. |
Display
| Setting | Type | Default | What it controls |
|---|---|---|---|
| Direction | Horizontal / Vertical | Horizontal | A row, or a column. |
| Dividers | toggle | on | Lines between the segments. |
Colors
| Setting | Type | Default | What it controls |
|---|---|---|---|
| Selected | colour | theme accent | The selected segment. |
| Unselected | colour | theme | The other segments. |
| Background | colour | theme | Behind the segments. |
| Text | colour | theme | The labels. |

States
- Run mode — a tap selects the segment and writes its value; the previous one goes flat. Only one at a time.
- Set by the device or a rule — writing a segment’s value to the signal selects it on the dashboard.
- Device offline — a mode is a state:
ISignalwith Restore brings it back on reconnect.
Arduino device code
The address is all the device knows — I5 here; use the one the app gave your signal. In the sketch, index is the value of the segment that was tapped:
ISegmentedSwitch(I5, int index) { … };
Complete sketch — Cloud
Paste it into the Arduino IDE, put your Wi-Fi and the token the app gave you, upload.
#include <InstantIoT.h>
const char* WIFI_SSID = "MyWiFi";
const char* WIFI_PASS = "MyPassword";
const char* DEVICE_TOKEN = "PASTE_TOKEN_HERE";
int mode = 0; // 0 off · 1 auto · 2 manual — the segment values
ISegmentedSwitch(I5, int index) {
mode = index;
Serial.print("Mode -> "); Serial.println(mode);
};
void setup() {
Serial.begin(115200);
InstantIoT.begin(WiFiLink(WIFI_SSID, WIFI_PASS), Cloud(DEVICE_TOKEN));
}
void loop() {
InstantIoT.loop();
if (mode == 1) { /* auto: the device decides */ }
if (mode == 2) { /* manual: the app decides */ }
}
Other connections
The widget block never changes. Only the begin() line says how the device reaches the app:
| Connection | begin() |
Devices |
|---|---|---|
| Cloud over Wi-Fi (above) | InstantIoT.begin(WiFiLink("MyWiFi", "secret"), Cloud(DEVICE_TOKEN)); |
ESP32 family, ESP8266, UNO R4 WiFi, MKR WiFi 1010, Nano 33 IoT, UNO WiFi Rev2 |
| Cloud over Ethernet | InstantIoT.begin(EthernetLink(), Cloud(DEVICE_TOKEN)); |
any board + an Ethernet shield |
| Direct — the device’s own Wi-Fi | InstantIoT.begin(AccessPoint("MyESP32", "12345678")); |
every board with Wi-Fi |
| Direct — Bluetooth LE | InstantIoT.begin(BLELink("MyESP32")); — #include <NimBLEDevice.h> first |
ESP32 family (not the S2) |
| Direct — Bluetooth Classic | InstantIoT.begin(BluetoothLink("MyESP32")); |
the original ESP32, Android only |
| Direct — a Bluetooth module (HC-05, HM-10) | InstantIoT.begin(SerialLink(Serial1)); — or SerialLink(13, 15) on ESP8266, SerialLink(10, 11) on UNO / Nano |
every board, radio or not |
| Your own InstantIoT Server (open source, at home) | InstantIoT.begin(WiFiLink("MyWiFi", "secret"), MyServer("192.168.1.42", DEVICE_TOKEN)); |
same as Cloud |
Direct needs no token: the phone is at the other end of the wire. See Connect for TLS, timeouts and what to do when it does not connect.
ISignaldoes the same job — and survives a restart.ISignal(I5, int v)runs with exactly the same value asISegmentedSwitch(I5, int index): the widget block is the readable form,ISignalthe generic one, and you can use either. The difference shows when the device reconnects: with Restore after a restart on the signal, the Cloud sends the last value again and only theISignalblock runs — a mode is a state —ISignal(I5, int index)with Restore on, and the device wakes up in the mode you left it in. See One block for everything.
Notes
- Give the segments the values your sketch already uses (
0, 1, 2for anenum) rather than translating in the block. - Three or four segments read well; five is the maximum and gets tight on a phone.
- The same signal can be set by a rule at a set time — the switch on the dashboard follows.
Next
→ Switch — two states only → Advanced Button — one value per gesture, momentary