accelerometer
Category:Circuit
The accelerometer
is an object representing the accelerometer sensor attached to the Circuit Playground.
Properties and Methods
accelerometer.getOrientation()
- Get the orientation of the board (i.e tilting forward, back, side to side, spinning, etc)accelerometer.getAcceleration()
-
Events
The accelerometer has a fair amount of event types as well.
Event | Description |
---|---|
Change | Fired any time the accelerometer experiences a change |
Data | Fires every 50 milliseconds |
Single Tap | Fires only when a tap is detected next to the board. |
Double Tap | Fires only when two taps within x amount of time of each other is detected next to the board. |
Examples
Tilt Detector
Lights up the color LEDs based on how the board is being tilted.
var colors = "white";
onBoardEvent(accelerometer, "data", function(event) {
var pitch = accelerometer.getOrientation("pitch");
var inclination = accelerometer.getOrientation("inclination");
var roll = accelerometer.getOrientation("roll");
//front to back
if (pitch < -10) {
colorLeds[0].on();
colorLeds[9].on();
}
if (pitch > 10) {
colorLeds[4].on();
colorLeds[5].on();
}
//side-to-side
if (roll > 20) {
colorLeds[7].on();
}
if(roll < -20){
colorLeds[2].on();
}
});
Syntax
accelerometer
Found a bug in the documentation? Let us know at support@code.org.