Switch Sensor
The Switch sensor class provides access to a switch sensor.
Constructor
Section titled “Constructor”Switch(options)
Section titled “Switch(options)”Creates a new Switch object instance.
Switch(options)Parameters
Section titled “Parameters”options
An object of properties used to construct the class.
sensor- The hardware connection definition.
interval(optional) - The sampling interval in milliseconds.
Instance Methods
Section titled “Instance Methods”sample()
Section titled “sample()”Returns a sample object containing the current switch state.
sample()Return Value
Section titled “Return Value”An object with the following property:
position- A number that represents the current state of the switch.
Examples
Section titled “Examples”const sensor = new device.sensor.Switch({ sensor: { io: device.io.Digital, pin: 0 }});
const sample = sensor.sample();console.log(`Switch position: ${sample.position}`);