objective c - How do I compare a constant value to a continuously-updated Accelerometer value each time round a loop? -


as suggested me in a previous post of mine, following code takes data coming accelerometer "minute" assignment : cmaccelerometerdata* data = [manager accelerometerdata]; performed, , then extracts data acceleration exercised on x-axis , stores value in double (double x) :

 cmmotionmanager* manager = [[cmmotionmanager alloc] init]; cmaccelerometerdata* data = [manager accelerometerdata]; double x = [data acceleration].x; 

suppose value stored 0.03 , suppose want use in while loop follows :

while (x > 0) { // } 

the above loop run forever

however, if used following code instead :

cmmotionmanager* manager = [[cmmotionmanager alloc] init]; while([[manager accelerometerdata] acceleration].x > 0) { // } 

wouldn't comparing 0 different value each time round loop? (which i'm going in project anyway..)

any thoughts?

the reason i'm asking following :

i want check values coming x-axis on period of time, rather keep checking them @ regular intervals, want write loop :

if ([[manager accelerometerdata] acceleration].x > 0 ) { // initialisetimer } while ([[manager accelerometerdata] acceleration].x > 0 ) { if( checktimer >=250ms ) { stoptimer; printout("x-axis acceleration greater 0 @ least 250ms"); breakfromloop; } } 

i know code in 2nd if-block isn't valid objective-c..this give idea of i'm going for..

this has simple solution.

1)declare instance variable x update each time accelerometer tell to.

2)compare x whatever value need in loop .

hope helps.

regards,

george


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -