I would like to sample data from the x axis of an accelerometer using python, and once the movement has exceeded a threshold I want to activate an alarm.
The dilemma I have is the accelerometer is not always level, and I want to take this into consideration, so that if the accelerometer is angled and the readings thereafter are the same, no alarm will be raised.
can anybody point to a sample code
I have started the following code, but it is not complete maybebe someone can finish it
[x, y, z] = adxl345.getAxes()
valAccel_x = x
current_x = x
if abs(current_x - old_x)>0.035:
print ("threshold breached")
old_x = current_x