Skip to content

Accelerometer Sensor

The Accelerometer sensor class provides access to a three-dimensional accelerometer.

Creates a new Accelerometer object instance.

Accelerometer(options)

options

An object of properties used to construct the class.

sensor - The hardware connection definition.

interval (optional) - The sampling interval in milliseconds.

Returns a sample object containing the current acceleration data.

sample()

An object with the following properties:

x - A number that represents the sampled acceleration along the x axis in meters per second squared.

y - A number that represents the sampled acceleration along the y axis in meters per second squared.

z - A number that represents the sampled acceleration along the z axis in meters per second squared.

const accel = new device.sensor.Accelerometer({
sensor: {
io: device.io.I2C,
address: 0x19
}
});
const sample = accel.sample();
console.log(`X: ${sample.x}, Y: ${sample.y}, Z: ${sample.z}`);

Accelerometer