
> [Switch Class Reference](https://obniz.github.io/obniz/obnizjs/classes/obnizcore.components.obnizswitch.html)
> [Switch API Reference](/reference/websocket/switch)

If a device has a switch, you can read or monitor it. For obniz Board series, it's on left-top.

[switch.getWait()](https://obniz.github.io/obniz/obnizjs/classes/obnizcore.components.obnizswitch.html#getwait) read current switch status as a string. [switch state](https://obniz.github.io/obniz/obnizjs/modules/obnizcore.components.html#obnizswitchstate) describe list of stats. And helper function [stateWait()](https://obniz.github.io/obniz/obnizjs/classes/obnizcore.components.obnizswitch.html#statewait) will wait for until specified state.

```javascript
// Javascript Example

var state = await obniz.switch.getWait();
if (state === "push") {
  console.log("pressed")
}

```

#### Monitor

Register a function to [switch.onchange](https://obniz.github.io/obniz/obnizjs/classes/obnizcore.components.obnizswitch.html#onchange). The function will receive all switch state changes.

```javascript
// Javascript Example

obniz.switch.onchange = function(state) {
  if (state === "push") {
    console.log("pressed")
  }
}

```

Switch monitoring can't be disabled like io.input().
