Switch

Switch Class Reference
Switch API Reference

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

switch.getWait() read current switch status as a string. switch state describe list of stats. And helper function stateWait() will wait for until specified state.

// Javascript Example

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

Monitor

Register a function to switch.onchange. The function will receive all switch state changes.

// Javascript Example

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

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