Maximum Acceleration Reading

Discussion in 'iPhone/iPad Programming' started by freshking, Feb 15, 2009.

  1. macrumors newbie

    Joined:
    Feb 15, 2009
    #1
    Hi,

    in my app I use acceleration values. I have no problem reading and using them.
    But now I want to read maximum acceleration values and store them. And if a new value which is larger pops up the old one gets updated. Just like a max needle in one of those acceleration meter apps.
    I kind of have no idea how i'm supposed to do that. I always end up recieving the current values the accelerometer is recieving.
    If somebody could show me how to do this, that would be really great. I think I have tried everything and have gotten nowhere.
    Thanks alot!
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    I think you'll need to create a variable to store the maximum acceleration value. When you read the current value, compare it to your stored value. If it's greater, update the max to the new value.
     
  3. thread starter macrumors newbie

    Joined:
    Feb 15, 2009
    #3
    Thats also how I would do it but there still are some issues. Some code to get started would be a really big help!
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    What kinds of issues?
    You mean, like this?
    Code:
    float currentX = acceleration.x;
    if (currentX > maxX)
        maxX = currentX;
     
  5. thread starter macrumors newbie

    Joined:
    Feb 15, 2009
    #5
    Thats kind of also what I have been working on.
    Assuming your maxX is a float value these are the values i get for maxX:

    They constantly change up or down but I only want the maximum value.
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    You sure you're outputting maxX and not currentX?
    For example, for the third value, 0.054506 is not greater than 0.999273, so maxX would not be updated (i.e. the if fails).
     
  7. thread starter macrumors newbie

    Joined:
    Feb 15, 2009
    #7
    My bad. Thanks for the code. Works perfectly.
     

Share This Page