Rotation

Find how much the Adafruit Circuit Playground Express is tilted in one direction.

input.rotation(Rotation.Roll);

The Adafruit Circuit Playground Express has a part on it called the accelerometer that can check the ways that the Adafruit Circuit Playground Express is moving.

Parameters

  • kind the direction you are checking:
    • Pitch: up or down
    • Roll: left or right

Returns

  • a number that tells how much the Adafruit Circuit Playground Express is tilted in the direction you say, from 0 to 360 degrees

Example: Adafruit Circuit Playground Express leveler

This program helps you move the Adafruit Circuit Playground Express until it is level. When it is leveled, the message “LEVELED” appears at the console.

let roll = 0
let pitch = 0
forever(() => {
    pitch = input.rotation(Rotation.Pitch)
    roll = input.rotation(Rotation.Roll)
    if (Math.abs(pitch) < 10 && Math.abs(roll) < 10) {
        console.log("LEVELED")
    }
})

Simulator

If you are running this program in a browser, you can tilt the Adafruit Circuit Playground Express with your mouse.

See also

acceleration

accelerometer