Button Widget
The Button widget sends a value to a virtual pin when pressed. It supports two modes: Push (momentary — sends a value on press, another on release) and Toggle (latching — alternates between on and off values with each click).
Default size: 2 × 2 grid cells
Configuration
| Property | Type | Default | Description |
|---|---|---|---|
mode | push | toggle | push | Controls press behavior |
onValue | string | 1 | Value sent on press / when toggled ON |
offValue | string | 0 | Value sent on release (push) / when toggled OFF |
color | hex color | #3B82F6 | Button accent color |
| Device | device | — | The device to write to |
| Pin | V0–V255 | — | The virtual pin to write to |
| Label | string | — | Widget label shown above the button |
Modes in detail
Push mode
Acts like a doorbell — sends onValue the moment you press it, and sends offValue the moment you release it.
Use this to trigger momentary actions: a servo pulse, a buzzer beep, or a HTTP request on the device.
VWIRE_RECEIVE(V0) {
int v = param.asInt();
if (v == 1) {
// button pressed — fire relay
digitalWrite(RELAY, HIGH);
} else {
// button released — cut relay
digitalWrite(RELAY, LOW);
}
}
Toggle mode
Latches between onValue and offValue on each click. The button visually stays "on" or "off".
Use this for persistent state: a light that stays on until pressed again.
VWIRE_RECEIVE(V1) {
int state = param.asInt();
digitalWrite(LED_PIN, state);
// save to NVS if you want to survive reboots
}
Firmware tips
- Echo back the state after writing to the pin so the button stays in sync if the device rejects the command:
VWIRE_RECEIVE(V1) {
int state = param.asInt();
bool accepted = digitalWrite(LED_PIN, state) == 0;
if (!accepted) state = !state; // if failed, invert
Vwire.virtualSend(V1, state); // echo actual state
} - Use
Vwire.syncVirtual(V1)insetup()to restore toggle state after a reboot.