Skip to main content

Accelerometer

A 3-axis accelerometer.

An accelerometer module should translate acceleration values as follows:

OrientationX value (g)Y value (g)Z value (g)
Module lying flat00-1
Module on left edge-100
Module on bottom edge010
import { Accelerometer } from "@devicescript/core"

const accelerometer = new Accelerometer()

Registers

reading

Indicates the current forces acting on accelerometer.

  • track incoming values
import { Accelerometer } from "@devicescript/core"

const accelerometer = new Accelerometer()

accelerometer.reading.subscribe(async (value) => {
...
})

readingError

Error on the reading value.

  • read only
import { Accelerometer } from "@devicescript/core"

const accelerometer = new Accelerometer()

const value = await accelerometer.readingError.read()
  • track incoming values
import { Accelerometer } from "@devicescript/core"

const accelerometer = new Accelerometer()

accelerometer.readingError.subscribe(async (value) => {
...
})

readingRange

Configures the range forces detected. The value will be "rounded up" to one of max_forces_supported.

  • read and write
import { Accelerometer } from "@devicescript/core"

const accelerometer = new Accelerometer()
// ...
const value = await accelerometer.readingRange.read()
await accelerometer.readingRange.write(value)
  • track incoming values
import { Accelerometer } from "@devicescript/core"

const accelerometer = new Accelerometer()

accelerometer.readingRange.subscribe(async (value) => {
...
})

Events

tiltUp

Emitted when accelerometer is tilted in the given direction.

accelerometer.tiltUp.subscribe(() => {

})

tiltDown

Emitted when accelerometer is tilted in the given direction.

accelerometer.tiltDown.subscribe(()=>{

})

tiltLeft

Emitted when accelerometer is tilted in the given direction.

accelerometer.tiltLeft.subscribe(()=>{

})

tiltRight

Emitted when accelerometer is tilted in the given direction.

accelerometer.tiltRight.subscribe(()=>{

})

faceUp

Emitted when accelerometer is laying flat in the given direction.

accelerometer.faceUp.subscribe(()=>{

})

faceDown

Emitted when accelerometer is laying flat in the given direction.

accelerometer.faceDown.subscribe(()=>{

})

freefall

Emitted when total force acting on accelerometer is much less than 1g.

accelerometer.freefall.subscribe(()=>{

})

shake

Emitted when forces change violently a few times.

accelerometer.shake.subscribe(()=>{

})

force2g

Emitted when force in any direction exceeds given threshold.

accelerometer.force2g.subscribe(()=>{

})

force3g

Emitted when force in any direction exceeds given threshold.

accelerometer.force3g.subscribe(()=>{

})

force6g

Emitted when force in any direction exceeds given threshold.

accelerometer.force6g.subscribe(()=>{

})

force8g

Emitted when force in any direction exceeds given threshold.

accelerometer.force8g.subscribe(()=>{

})

help

The "deviceScript" contains more information that can be helpful in answering questions related to the device. You can refer to it for better understanding and troubleshooting.