43 lines
1.1 KiB
Markdown
43 lines
1.1 KiB
Markdown
# Acceleration
|
|
|
|
Get the acceleration value (milli g-force), in one of three specified dimensions.
|
|
|
|
Find the acceleration of the micro:bit (how fast it is speeding up or slowing down).
|
|
|
|
```sig
|
|
input.acceleration(Dimension.X);
|
|
```
|
|
|
|
## ~hint
|
|
|
|
You measure acceleration with the **milli-g**, which is 1/1000 of a **g**.
|
|
A **g** is as much acceleration as you get from Earth's gravity.
|
|
|
|
## ~
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
* which direction you are checking for acceleration, either `Dimension.X` (left and right), `Dimension.Y` (forward and backward), or `Dimension.Z` (up and down)
|
|
|
|
### Returns
|
|
|
|
* a [number](/reference/types/number) that means the amount of acceleration. When the micro:bit is lying flat on a surface with the screen pointing up, `x` is `0`, `y` is `0`, and `z` is `-1023`.
|
|
|
|
### Example: bar chart
|
|
|
|
This example shows the acceleration of the micro:bit with a bar graph.
|
|
|
|
```blocks
|
|
basic.forever(() => {
|
|
led.plotBarGraph(input.acceleration(Dimension.X), 1023)
|
|
})
|
|
```
|
|
|
|
|
|
### See also
|
|
|
|
[compass-heading](/reference/input/compass-heading), [lightlevel](/reference/input/lightlevel)
|
|
|