1.1 KiB
1.1 KiB
Rotation
Get a rotation angle in degrees inferred from the accelerometer readings.
input.rotation(Rotation.Roll);
Parameters
- kind: String - one of values specifying the kind of rotation:
pitch
(up/down around thex
axis);roll
(left/right around they
axis)
Returns
- Number - angle, in degrees.
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.
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(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`)
}
})