4. Accelerometer syntax

The accelerometer can measure changes in speed of movement in any direction.
The accelerometer also provides convenience functions for detecting gestures.
The recognised gestures are: up, down, left, right, face up, face down, freefall, 3g, 6g, 8g, shake.
The accelerometer range is from -2g to +2g.

4.1. Gesture Functions

Note

Gestures are not updated in the background so there needs to be constant calls to some accelerometer method to do the gesture detection. Usually gestures can be detected using a loop with a small sleep() delay.

accelerometer.current_gesture()

Return the name of the current gesture as a string. The gestures are: "up", "down", "left", "right", "face up", "face down", "freefall", "3g", "6g", "8g", "shake".

accelerometer.is_gesture(name)

Return True or False to indicate if the named gesture is currently active.

accelerometer.was_gesture(name)

Return True or False to indicate if the named gesture was active since the last call.

accelerometer.get_gestures()
Return a tuple of the gesture history. The most recent is listed last.
Also clears the gesture history before returning.

4.2. Acceleration Functions

accelerometer.get_x()

Return the acceleration measurement in the x axis, as a positive or negative integer, depending on the direction. The measurement is given in milli-g within the range of +/- 2000mg, registered on a scale of values from 0 to 1024.

accelerometer.get_y()

Return the acceleration measurement in the y axis, as a positive or negative integer, depending on the direction. The measurement is given in milli-g within the range of +/- 2000mg, registered on a scale of values from 0 to 1024.

accelerometer.get_z()

Return the acceleration measurement in the z axis, as a positive or negative integer, depending on the direction. The measurement is given in milli-g within the range of +/- 2000mg, registered on a scale of values from 0 to 1024.

accelerometer.get_values()

Return the acceleration measurements in all axes at once, as a three-element tuple of integers ordered as X, Y, Z, each within the range of +/-2000mg, registered on a scale of values from 0 to 1024.

accelerometer.get_strength()

Return the combined acceleration strength of all the axes, in milli-g, as a positive integer using pythagorean addition.