Chapter 6
Accelerometer
WHAT YOU WILL LEARN IN THIS CHAPTER:
- Learning about the accelerometer
- Using accelerometer methods
- Learning about options and arguments
So far, you’ve learned about basic events and how to detect them, and you’ve learned how to get basic information about the device, its network connectivity, and about notifications.
In the next three chapters, you’re going to learn about the accelerometer, the compass, and geolocation, starting with the accelerometer.
GETTING TO KNOW THE ACCELEROMETER
In this section, you’ll learn what the accelerometer is and what you can use it for.
What Is the Accelerometer?
The accelerometer is a device that captures motion in the X, Y, and Z directions.
To help visualize the X, Y, and Z directions, place your device face-up on a flat surface, like a desk. Ideally, this surface would offer very little friction so that, for example, you can push the device left and right without having to lift it. For the purposes of this example, let’s assume that wherever you put the device is 0, 0, 0 on a coordinate system. Any which way you move the device will result in a change of coordinates, either into the positive or negative quadrants.
If the device is flat on the surface of the desk, and you move it to the left or right, you’ve moved it along the X axis. Moving it to the left gives you a negative result; moving it to the right gives you a positive result. If you were to move the device away from you on the desk or toward you, you’re moving ...