The accelerometer
The accelerometer is used to detect movement of the device. It sends out updates of the device's position on any of the three axes, that is, left/right, up/down, and forward/backward. To use the accelerometer, you define a listener to Ti.Accelerometer
. Once you have this event listener defined, your code will be called every time the accelerometer detects movement of the device.
Tip
Be kind to your user's phones! Remove the event listener to Ti.Accelerometer
when you have finished with it. The accelerometer will continue to provide constant updates of the device's position and drain the battery as long as you retain the event listener. Be frugal with the gadget, conserve battery life, and be sure to remove the event listener when you are finished with it by calling Ti.Accelerometer.removeEventListener
.
In this first example, we will compute the pitch of the device and display it on a slider.