views:

193

answers:

4

I want to do this: If the device moves (accelerometer values change), then I want to adjust some values in my view according to that movement.

Would I invoke a method every time an accelerometer value changes? I believe that would be a bad idea, since they might refresh too often.

+1  A: 

If you're worried about too frequent changes, just use an accumulator; use a little bit of code that detects the changes, and checks the system time; only if enough system time has passed, do you fire the (potentially accumulated) change method.

McWafflestix
yeah that sounds pretty good. So that accumulator is a sleek and lightweight method I implement somewhere (where?)?
Thanks
+1  A: 

I think so... If not you have only one option. Getting a reading periodically. Again shorter the period, higher the accuracy. So it might be more efficient if you can trigger an event when a change in value is detected.

Chathuranga Chandrasekara
+1  A: 

If you are concerned about noise coming from the accelerometer you can smooth out the inputs by implementing a moving average. This will allow you to take samples however frequently you want without worrying about false starts coming from the accelerometer.

http://en.wikipedia.org/wiki/Moving_average

Antonio Haley
great idea. Thanks!
Thanks
+1  A: 

When you implement the accelerometer:didAccelerate: method in your UIAccelerometerDelegate, just have an if statement, checking if the time between the last time you got an update if long enough.

In your class that implements UIAccelerometerDelegate, you can have a property that holds something like lastTimeUpdated and then update it whenever you change your view

Benny Wong
and in the meantime i'll calculate the moving average of the measurements, to get an better value, right?
Thanks