Accelerometer Sensor
The Accelerometer sensor class provides access to a three-dimensional accelerometer.
Constructor
Section titled “Constructor”Accelerometer(options)
Section titled “Accelerometer(options)”Creates a new Accelerometer object instance.
Accelerometer(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 acceleration data.
sample()Return Value
Section titled “Return Value”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.
Examples
Section titled “Examples”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}`);