pxt-calliope/docs/reference/input/rotation.md

49 lines
1.1 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# Rotation
Get a rotation angle in degrees inferred from the accelerometer readings.
```sig
input.rotation(Rotation.Roll);
```
### Parameters
2016-04-13 17:27:45 +02:00
* kind: [String](/reference/types/string) - one of values specifying the kind of rotation: ``pitch`` (up/down around the ``x`` axis); ``roll`` (left/right around the ``y`` axis)
2016-03-26 00:47:20 +01:00
### Returns
2016-04-13 17:27:45 +02:00
* [Number](/reference/types/number) - angle, in degrees.
2016-03-26 00:47:20 +01:00
### Example: micro:bit leveller
The following example uses the `rotation` and the `plot leds` function to help you move the BBC micro:bit until it's level: when it is level, a smiley shows up on the screen. When running this code in a web browser, move your mouse to simulate the rotation.
```sig
basic.forever(() => {
let pitch = input.rotation(Rotation.Pitch)
let roll = input.rotation(Rotation.Roll)
if (Math.abs(pitch) < 10 && Math.abs(roll) < 10) {
basic.plotLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
} else {
basic.plotLeds(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`)
}
})
```
### See also
2016-04-13 17:27:45 +02:00
[acceleration](/reference/input/acceleration), [compass-heading](/reference/input/compass-heading)
2016-03-26 00:47:20 +01:00