Reputation: 1345
I want to create an iPhone application that executes certain actions based on what direction you tilt your device. For instance if you tilt the device so your phone screen is pointing towards the floor execute action x, if you tilt your phone so the phone screen is pointing towards the sky execute action y. I found some examples using the iPhones accelerometer in order to detect the tilt of the phone, but the values the accelerometer generated were so sporadic it was hard to execute a certain action based on specific values.
I'm relatively new to using the accelerometer within applications so I might be going about this completely the wrong way, any help would be appreciated.
Upvotes: 2
Views: 83
Reputation: 8741
The raw data out of the accelerometer is pretty jittery. You'll want to apply a high pass filer or a low pass filter at a minimum to the raw data. See the Apple sample code AccelerometerFilter.m for some basics on how to use it. I found that that wasn't sufficient and I keep a time-moving average of the data to accomplish what I need. You'll certainly need to play around with this to get it to do what you want it to do.
Upvotes: 3