Chapter 10. Using sensors

 

This chapter covers

  • Understanding Sensor API design
  • Interpreting sensor data
  • Using sensors in the emulator
  • Moving with the motion sensor

You can build cool applications by combining sensors with other features of the phone. Applications may respond to a user shaking the device by randomly selecting an object or clearing the screen. Games can use the device’s movement as an input mechanism, turning the whole phone into a game controller. Another class of applications augments the real world with computer-generated information. Augmented reality apps can show you the location of friends nearby in relation to your current location. Astronomy applications determine the position of your device and identify the stars in the night sky. A tourist application may be able to identify nearby landmarks.

All these applications require sensor input from the physical world. The phone’s accelerometer, compass, and gyrometer sensors capture input from the real world and serve the data to applications through the Windows Phone SDK’s Sensor API. When combined with location data from the phone’s Location Service, stunning augmented-reality applications are possible. We discuss the Location Service in chapter 16.

10.1. Understanding the Sensor APIs

10.2. Creating the sample application

10.3. Measuring acceleration with the accelerometer

10.4. Finding direction with the compass

10.5. Pivoting with the gyrometer

10.6. Wrapping up with motion

10.7. Summary