First of all sorry for the silly question.
What i'm trying to do is capture the accelerometer data for each second for three seconds and do addition of that data, but due to lack of experience i'm finding it hard time to do it.
What I've accomplished till now is:
Get acceleration data of X,Y,X axes in real time and calculated resultant acceleration as resultant_acceleration = Math.sqrt(X^2+y^2+z^2) that is real time as well and keeps changing with time.
What i want to do is:
Find resultant_acceleration at end of first, second and third second,i.e a1,a2,a3 and return (a1+a2+a3) I'm going through hard times to write a method in java that does the task.
public void onSensorChanged(SensorEvent event) {
final ArrayList<Double> accln = new ArrayList<>();
//enter your code here
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
if (!mInitialized) {
mLastX = x;
mLastY = y;
mLastZ = z;
mInitialized = true;
} else {
float deltaX = Math.abs(mLastX - x);
float deltaY = Math.abs(mLastY - y);
float deltaZ = Math.abs(mLastZ - z);
if (deltaX < NOISE) deltaX = (float) 0.0;
if (deltaY < NOISE) deltaY = (float) 0.0;
if (deltaZ < NOISE) deltaZ = (float) 0.0;
mLastX = x;
mLastY = y;
mLastZ = z;
final double a =Math.sqrt((deltaX*deltaX)+(deltaY*deltaY)+(deltaZ*deltaZ));
accln.add(a); //what i am trying to do here is collect the sample data of acceleration in an array list for 3 seconds,// so later i can calculate average acceleration
}
}