Chapter 8. Using sensors

 

This chapter covers

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

Some really cool applications can be built combining sensors with other features of the phone. Applications might 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, basically 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 relative to your current location. Astronomy applications determine the position of your device and identify the stars in the night sky. A tourist application might be able to identify nearby landmarks.

All of these applications require sensor input from the physical world. The phone’s accelerometer, compass, and gyroscope 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 13.

8.1. Understanding the sensor APIs

8.2. Creating the sample application

8.3. Measuring acceleration with the accelerometer

8.4. Finding direction with the Compass

8.5. Pivoting with the Gyroscope

8.6. Wrapping up with the motion sensor

8.7. Summary