Skip to content

Gyroscope Sensor

The Gyroscope sensor class provides access to a three-dimensional gyroscope.

Creates a new Gyroscope object instance.

Gyroscope(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 angular velocity data.

sample()

An object with the following properties:

x - A number that represents the sampled angular velocity around the x axis in radians per second.

y - A number that represents the sampled angular velocity around the y axis in radians per second.

z - A number that represents the sampled angular velocity around the z axis in radians per second.

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

Gyroscope