0

In my iPhone application i am using Accelerometer to find the movement of the device.

using some formula I am finding a int value (P) with the x,y and z acceleration. this P value is being found in every .5 seconds.

I want to show an alert if the P value is same for continuous 4 times. How to do this.

2 Answers2

1

You could use a queue data structure (you can find Objective-C implementation here) with a length of 4. After enqueuing new element you should check if all elements in the queue are equal (assuming they're integers).

Community
  • 1
  • 1
Arek Holko
  • 8,966
  • 4
  • 28
  • 46
1

I have declared one more integer Q. and if P is a particular value - I am incrementing Q else making Q = 0. And when Q = 4 I am doing my stuff.