obniz to be used
When the switch state changes, this callback function will be called. If you press and release a switch, it callbacks twice ("push" and "none").
// Javascript Example
obniz.display.clear();
obniz.switch.onchange = function(state) {
if (state === "push") {
obniz.display.print("Pushing");
} else {
obniz.display.clear();
}
}
current switch state
Rsponse waiting timeout in milliseconds
Calls each of the listeners registered for a given event.
Return an array listing the events for which the emitter has registered listeners.
This determines the current status of the switch.
// Javascript Example
obniz.display.clear();
var state = await obniz.switch.getWait();
if (state === "push") {
obniz.display.print("Now Pressed");
}
Return the number of listeners listening to a given event.
Return the listeners registered for a given event.
Add a listener for a given event.
Add a one-time listener for a given event.
Remove all listeners, or those of the specified event.
Remove the listeners of a given event.
With this you wait until the switch status changes to state.
// Javascript Example
await obniz.switch.stateWait("push");
console.log("switch pushed");
await obniz.switch.stateWait("left");
console.log("switch left");
await obniz.switch.stateWait("right");
console.log("switch right");
await obniz.switch.stateWait("none");
console.log("switch none");
state for wait
Generated using TypeDoc
The embedded switch on obniz Board.