Events
The input.onGesture allows to run code on a number of pre-defined gestures such as shake, freefall or various orientation events.
Live data
The input.acceleration returns the immediate acceleration for a given direction in milli-g, e.g. 1/1000 of a g. The measure includes earth gravity (1000mg) You can query X, Y, Z or the strength.
If you look closely at the center of the Circuit Playground, you will see the accelerometer axis printed on the board.
Assuming the board is at rest on a table,
- the
Xaxis is aligned horizontally from left to right. If you tilt left,Xis negative, tilt rightXis positive. - the
Yaxis is aligned vertically from bottom to top. If you tilt forward,Yis positive, tilt backwardYis negative. - the
Zaxis is perpendicular to the board and pointing down. At rest,Zis aligned with earth gravity.
Example
The example below plays a sound when the Circuit Playground is shaken. In a forever loop, it display the accelerometer reading using graph.
Page last edited June 07, 2017
Text editor powered by tinymce.