Display Values from Multiple Sensors
So far we’ve worked with the accelerometer, which is a hardware motion sensor built into the Android device. In future chapters we’ll want to work with multiple sensors, so let’s fire up a few simultaneously and display their values on the Android screen. For this sketch, we’ll activate the accelerometer again and add two position sensors and an environment sensor. The magnetic field sensor and the proximity sensors are considered position sensors; the light sensor is an environment sensor.
We could store the three axes returned by the accelerometer and magnetometer sensors in individual floating point variables. A better solution, however, is to work with Processing’s PVector class.[70] It can store either ...
Get Rapid Android Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.