Accelerometer¶
This object gives you access to the on-board accelerometer. 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.
Functions¶
-
microbit.accelerometer.get_x()¶ Get the acceleration measurement in the
xaxis, as a positive or negative integer, depending on the direction.
-
microbit.accelerometer.get_y()¶ Get the acceleration measurement in the
yaxis, as a positive or negative integer, depending on the direction.
-
microbit.accelerometer.get_z()¶ Get the acceleration measurement in the
zaxis, as a positive or negative integer, depending on the direction.
-
microbit.accelerometer.get_values()¶ Get the acceleration measurements in all axes at once, as a three-element tuple of integers ordered as X, Y, Z.
-
microbit.accelerometer.current_gesture()¶ Return the name of the current gesture.
注解
MicroPython understands the following gesture names: "up", "down",
"left", "right", "face up", "face down", "freefall",
"3g", "6g", "8g", "shake". Gestures are always
represented as strings.
-
microbit.accelerometer.is_gesture(name)¶ Return True or False to indicate if the named gesture is currently active.
-
microbit.accelerometer.was_gesture(name)¶ Return True or False to indicate if the named gesture was active since the last call.
-
microbit.accelerometer.get_gestures()¶ Return a tuple of the gesture history. The most recent is listed last. Also clears the gesture history before returning.
Examples¶
A fortune telling magic 8-ball. Ask a question then shake the device for an answer.
Simple Slalom. Move the device to avoid the obstacles.