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

62 lines
1.4 KiB
Markdown
Raw Normal View History

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);
```
## ~hint
The @boardname@ has a part called the **accelerometer** that can
2016-11-02 01:44:37 +01:00
check how the @boardname@ is moving.
## ~
## 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
## Returns
2016-03-26 00:47:20 +01:00
Cherry picked fixes from v0 to v1 (#1476) * Fix example and do a few edits (#850) * Small fixes to the Karel project text (#862) * fix missing shadow type * add calibration info (#897) microbit-support:6348 User reported bug, but didn't realie micro:bit compass had to be calibrated on first run of the program. * Cherry pick adding various cross-editor compat APIs (#863) * fix nudge * Fix a typo ("screent") in the documentation (#1012) * Fix a typo "screent" -> "the LED screen" * Update showArrow doc string for consistency with other methods * Doc bugs found by xlators (#899) * Update rotation.md (#998) reflects actual behaviour of the board * fixed layout corruption (#1073) * Updating the new bug filer with the right link * Update challenges.md (#1325) For what I'm taught in school, 2 follows 1 :wink::wink:. * Update simulator.md (#1209) * Update plant watering.md (#1264) the connection to servo are male not female * support for MIDI simulator in v0 (#1331) * Doc improvements (#1337) * update grammar in radio-dashboard sample code * Chanllenge 2 follows 1 I open all challenges.md without "Challenge 2" and review the file `grep -r "Challenge 2" -L | grep challenge | xargs -I@ code @` Changes to be committed: modified: docs/lessons/counter/challenges.md modified: docs/lessons/game-counter/challenges.md modified: docs/lessons/night-light/challenges.md modified: docs/lessons/snowflake-fall/challenges.md * Revert "support for MIDI simulator in v0 (#1331)" This reverts commit 30a9c411fb80762656e7a636feff8e77b7fd9e67. * Revert "Cherry pick adding various cross-editor compat APIs (#863)" This reverts commit 7308dbef23e9ee402bebb7e721d7014d8252c9e5. * Fixed pin needed to replace button A (#1385) * Cherry pick part of the signature update in in2cWriteBuffer (#863): 7308dbe
2018-10-22 19:00:57 +02:00
* a [number](/types/number) that means how much the microbit is tilted in the direction you say; for `Rotation.Pitch` from `-90` to `90` degrees and for `Rotation.Roll` from `-180` to `180` degrees.
2016-03-26 00:47:20 +01:00
## Example: @boardname@ leveler
2016-03-26 00:47:20 +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
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.
```blocks
let pitch = 0;
2016-03-26 00:47:20 +01:00
basic.forever(() => {
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) {
basic.showLeds(`
. # . # .
. . . . .
. . . . .
# . . . #
. # # # .
`);
2016-03-26 00:47:20 +01:00
} else {
basic.showLeds(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`);
}
});
2016-03-26 00:47:20 +01: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