You need to calculate the current average of the values. To do this, you need to save the last values ββof n in the array, and then click and squeeze the values ββfrom the array when you read the accelerometer data. Here are a few pseudo codes:
const SIZE = 10; float[] xVals = new float[SIZE]; float xAvg = 0; function runAverage(float newX){ xAvg += newX/SIZE; xVals.push(newX); if(xVals.length > SIZE){ xAvg -= xVals.pop()/SIZE; } }
You need to do this for all three axes. Play with the SIZE value; the larger it is, the smoother the value, but slow things seem to react. It depends on how often you read the value of the accelerometer. If it is read 10 times per second, then SIZE = 10 may be too large.
source share