2016-03-26 00:47:20 +01:00
|
|
|
# Rotation
|
|
|
|
|
2016-11-02 01:44:37 +01:00
|
|
|
Find how much the @boardname@ is tilted in different directions.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```sig
|
|
|
|
input.rotation(Rotation.Roll);
|
|
|
|
```
|
|
|
|
|
2016-06-10 03:25:59 +02:00
|
|
|
## ~hint
|
|
|
|
|
2016-11-01 18:42:42 +01:00
|
|
|
The @boardname@ has a part called the **accelerometer** that can
|
2016-11-02 01:44:37 +01:00
|
|
|
check how the @boardname@ is moving.
|
2016-06-10 03:25:59 +02:00
|
|
|
|
|
|
|
## ~
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Parameters
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-07-15 23:53:52 +02:00
|
|
|
* ``kind`` means which direction you are checking: `Rotation.Pitch` (up and down) or `Rotation.Roll` (left and right)
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Returns
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2018-04-27 20:25:17 +02:00
|
|
|
* a [number](/types/number) that means how much the microbit is tilted in the direction you say, from `-180` to `180` degrees
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Example: @boardname@ leveler
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-11-01 18:42:42 +01:00
|
|
|
This program helps you move the @boardname@ until it is level. When
|
2016-11-02 01:44:37 +01:00
|
|
|
it is level, the @boardname@ shows a smiley.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-06-10 03:25:59 +02:00
|
|
|
If you are running this program in a browser, you can tilt the
|
2016-11-02 01:44:37 +01:00
|
|
|
@boardname@ with your mouse.
|
2016-06-10 03:25:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
let pitch = 0;
|
2016-03-26 00:47:20 +01:00
|
|
|
basic.forever(() => {
|
2016-06-10 03:25:59 +02:00
|
|
|
pitch = input.rotation(Rotation.Pitch);
|
|
|
|
let roll = input.rotation(Rotation.Roll);
|
2016-03-26 00:47:20 +01:00
|
|
|
if (Math.abs(pitch) < 10 && Math.abs(roll) < 10) {
|
2016-06-10 03:25:59 +02:00
|
|
|
basic.showLeds(`
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
# . . . #
|
|
|
|
. # # # .
|
|
|
|
`);
|
2016-03-26 00:47:20 +01:00
|
|
|
} else {
|
2016-06-10 03:25:59 +02:00
|
|
|
basic.showLeds(`
|
|
|
|
# . . . #
|
|
|
|
. # . # .
|
|
|
|
. . # . .
|
|
|
|
. # . # .
|
|
|
|
# . . . #
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
});
|
2016-03-26 00:47:20 +01:00
|
|
|
```
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## See also
|
2016-03-26 00:47:20 +01:00
|
|
|
|
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
|
|
|
|