Skip to main content

Button Widget

⚡ Control

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

PropertyTypeDefaultDescription
modepush | togglepushControls press behavior
onValuestring1Value sent on press / when toggled ON
offValuestring0Value sent on release (push) / when toggled OFF
colorhex color#3B82F6Button accent color
DevicedeviceThe device to write to
PinV0V255The virtual pin to write to
LabelstringWidget 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) in setup() to restore toggle state after a reboot.