1

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.

tsdexter
  • 2,911
  • 4
  • 36
  • 59
  • "*... the user moves the phone ... how far and fast.*" [Can't do it](http://stackoverflow.com/q/7829097/341970) due to the inaccuracy of the gyros. Try to rethink your application in such a way that you use orientation instead. Orientation will work well. – Ali Sep 06 '13 at 18:13
  • @Ali OK, well I don't necessarily need distance and speed, just up/down, it will be the exact same repetitive up/down movement for the most part so I can instead have a user-set calibration for distance/speed. So basically a shake motion with an output of when it's up and when it's down...make sense? Is that possible? – tsdexter Sep 06 '13 at 18:29
  • Well, if you need nothing accurate, then, probably, you can get the direction at least. I have never tried that though... – Ali Sep 06 '13 at 18:36

0 Answers0