Goal: The objective here was to generate a simple event using Accelerometer.
Initially we will assume that the phone is at rest on a surface. Hence the initial values of [x,y,z] will be [0,0,-1]. Then we will simulate an event that the phone is thrown and is falling down and gravitational force is acting on it. During the fall the [x,y,z] values will change rapidly to cause a change in the accelerometer values. When the phone is falling it will display an alert message. When the phone strikes the ground, the [x,y,z] values will come to rest and so will the accelerometer values. Again an alert message will be generated indicating that the phone has striked the ground. The values generated have also been written to a log file to help in debugging the code.
1) Test.java - It is the class which is initially executed and which connects to Sensor Simulator. The functionality for capturing and displaying the [x,y,z] values is coded in this file.Fig 1. Figure below shows the initial UI screen with button "Throw the phone". |
Fig 2. Figure below shows the UI screen with accelerometer values for [x,y,z] and alert message of falling |
Fig 3. Figure below shows the UI screen with accelerometer values and alert messsage when phone has striked ground |
Fig 4. Figure below shows values written to the log file. |