Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hi I'm new to stack overflow, and to iOS applicationprogramming. I've learnt basic-intermediate Objective C coding and have done bits and pieces to do with actual iOS apps, but have not actually published one to the App Store yet.

The first one I'm interested in doing I just a basic app using the accelerometer. I want to make an app where there is a ruler on the iPhone's screen and you can move it along a flat object and in the end it will give you the length of it. I have read through the iOS documentation regarding the accerometer, but I don't know how to apply it to give me the distance of something...

Any help like links to read through, or code excerpts, or an open source app like it would be much appreciated!

share|improve this question
Hi, welcome to StackOverflow. Your message is not really a technical programming question StackOverflow is for. For example, you have not said what you have already tried, or exactly what problem you have. Typical questions on StackOverflow contain some code and are about specific problems. Please try to read out the accelerometer first by yourself. If you have any problems doing that, you can come back with a question. – Sjoerd Mar 28 at 7:50
possible duplicate of Need to find Distance using Gyro+Accelerometer – Ali Mar 28 at 9:15
possible duplicate of Android accelerometer accuracy (Inertial navigation) and probably many others – Ali Mar 28 at 9:15
Thanks for posting that. I had already seen that post. I was looking for something with more detail regarding the accelerometer and also how to get something like a scrollview moving. I specifically didn't understand the statement: "So, once you have your accelerometer signals passed through a low-pass filter and binned in time with sampling interval dt, you can find the displacement in x" – falky Mar 28 at 10:48

closed as not a real question by Sjoerd, Banang, Ali, Monolo, Frank van Puffelen Mar 29 at 11:12

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

up vote 2 down vote accepted

Do you remember physics from school? Newton's laws of motion?

velocity = distance/time

so:

distance = velocity x time.

Acceleration is the change in velocity over time right? You do the rest...

Anyway, less rubbish, here's the Objective-C:

You'll need to conform to <UIAccelerometerDelegate> then you can:

    -(void)startMeasuringAcceleration{


        [[UIAccelerometer sharedAccelerometer] setUpdateInterval:0.125];
        [[UIAccelerometer sharedAccelerometer] setDelegate:self];

    }

    -(void)stopMeasuringAcceleration{

        [[UIAccelerometer sharedAccelerometer] setDelegate:nil];

    }

    //this is a delegate method
    - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{

        NSLog(@"%f, %f, %f, %f", acceleration.x, acceleration.y, acceleration.z, acceleration.timestamp);
}        
share|improve this answer
Awesome man! your a legend! Cheers! And yes we are literally doing that in physics at school right now! Thanks! – falky Mar 28 at 22:49
@falky: Note that even if this question has been closed, you can (should) "accept" the answer by clicking on the check mark if it helped. That gives some reputation points to you and to the author of the answer. – Martin R Apr 7 at 6:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.