UPDATE: as stated in the comments - distance and speed are not possible with the accuracy of the accelerometer - in that case, I would just need to calculate UP/DOWN repetition - is that possible?
I know you need some complex math on the accelerometer (and gyroscope?) but I'm not quite sure what I need to do - I'm new to this type of data.
What I want to do is detect when the user (in mobile safari, not native) moves the phone up or down in space and approximately how far and fast. I can't find any help on this, at least not for javascript.
I know I can get the Y accelerometer data with code like this:
window.ondevicemotion = function(event) {
y = event.accelerationIncludingGravity.y;
}
But I'm not entirely sure what to do after that...I did try to write some code on my own simply calculating the difference between y values like I would when using the scroll position on a web app but I realize now that that is way off and I need some pretty serious trig/vectors/complex math to get what I want... Any ideas?
Here's the totally going in the wrong direction (just calculating diffs) jsfiddle: http://jsfiddle.net/tsdexter/4AzjL/12/
Clarification: the basics of what I need to detect up/down/up/down/up/down/up/down movement and then I'll use the distance/speed/direction values to move an element on the screen in sync with the detected movement.