Chapter 9. Position sensors

 

In chapter 2, you shook your phone and made a sheep disappear using the phone’s accelerometer sensor. Most phones have sensors that can detect much smaller motions than a strong shake. You can see this when you tilt the phone to one side and the display rotates, or if you’ve played a driving game where you steer left and right by gently tilting the phone. Phones can tell which way up they’re facing—for instance, some people set their phone’s ringer to be silent automatically if the phone is face down on a desk. Your phone can also tell which direction is north by using its own built-in compass.

All the apps in this chapter rely on you using an actual phone, because the emulator doesn’t have any position sensors. Most phones will work with the apps in this chapter because the sensors you’re using are common. You can double-check exactly which sensors your phone has by downloading a free app from the Google Play Store such as the excellent Android Sensor Box from iMobLife (shown at right). You might find that your phone has some sensors that App Inventor can’t access yet (like a proximity or light sensor), but these features may be added to App Inventor as the sensors become common in more phones.

By the end of the chapter, you’ll have made apps that are controlled not by clicking buttons, but by altering the phone’s position in space. You’ll create an amazing magic trick and a simple motion-controlled game.

Compass app

Astonishing Prediction! app

Hungry Spider app

What did you learn?

Test your knowledge

Try it out

sitemap