Now it's time to program the initial tilt functionality!

The board's accelerometer allows us to sense which way the board is tilted.

What is an accelerometer? Most smart phones have accelerometers. They are used for example every time you turn your phone sideways or upright again. The screen adjusts accordingly because it knows which orientation it's experiencing, thanks to the accelerometer.

makecode_image.png
Smart phone accelerometer orientation. Source: Engadget

The way the accelerometer on the board works is that it can sense the amount of "gravity" it feels in 3 different axes.

makecode_image_ADZiECQJoA.jpeg
Circuit Playground Express Accelerometer

The three axes I'm talking about are the x, y, and z axis shown on the board above.

The gravity on the x axis is what we'll use to determine the pitch. The gravity on the y axis is what we'll use to determine volume.

makecode_image_KOv1kZYtbA.jpeg
3 dimensional axis. Source: intmath.com

So how do we measure gravity? In Gs!

1G is equivalent to Earth's gravitational pull at a resting point.

In this case we'll actually be using mgs which are milligravities! Meaning 1000mg is 1G. So if the board is tilted all the way in the x or y direction we will assume the accelerometer is feeling close to 1000mg or 1G in that direction. In this case we won't worry about the z axis which feels a constant 1G when the board is at rest as the z axis is perpendicular to gravity.

Now, with the accelerometer on the board, we can use gravity or mgs as an input to determine each pitch.

Learn more about the accelerometer on the Circuit Playground Express here.

This guide was first published on Apr 11, 2018. It was last updated on Apr 11, 2018.
This page (The Accelerometer) was last updated on Jun 18, 2020.