Proximity Sensor
The Proximity sensor class provides access to a proximity sensor or range finder.
Constructor
Section titled “Constructor”Proximity(options)
Section titled “Proximity(options)”Creates a new Proximity object instance.
Proximity(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 proximity data.
sample()Return Value
Section titled “Return Value”An object with the following properties:
near- A boolean that indicates if a proximate object is detected.
distance(optional) - A number that represents the distance to the nearest sensed object in centimeters.
max(optional) - A number that represents the maximum sensing range of the sensor in centimeters.
Examples
Section titled “Examples”const sensor = new device.sensor.Proximity({ sensor: { io: device.io.I2C, address: 0x39 }});
const sample = sensor.sample();if (sample.near) { console.log(`Object detected at ${sample.distance} cm`);}