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.
Rotation
Find how much the Adafruit Circuit Playground Express is tilted in one direction.
input.rotation(Rotation.Roll);
Parameters
kind
the direction you are checking:Pitch
: up or downRoll
: left or right
Returns
- a number that tells how much the Adafruit Circuit Playground Express is tilted in the direction you say, from
0
to360
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")
}
})
See also
accelerometer