PDA

View Full Version : Maximum Acceleration Reading




freshking
Feb 15, 2009, 06:23 AM
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!



dejo
Feb 15, 2009, 12:35 PM
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.

freshking
Feb 15, 2009, 01:05 PM
Thats also how I would do it but there still are some issues. Some code to get started would be a really big help!

dejo
Feb 15, 2009, 01:37 PM
Thats also how I would do it but there still are some issues.
What kinds of issues?
Some code to get started would be a really big help!
You mean, like this?
float currentX = acceleration.x;
if (currentX > maxX)
maxX = currentX;

freshking
Feb 15, 2009, 01:45 PM
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:

2009-02-15 20:42:15.402 G-Meter[645:20b] Acceleration value: 0.962936
2009-02-15 20:42:15.464 G-Meter[645:20b] Acceleration value: 0.999273
2009-02-15 20:42:15.500 G-Meter[645:20b] Acceleration value: 0.054506
2009-02-15 20:42:15.688 G-Meter[645:20b] Acceleration value: 0.181686
2009-02-15 20:42:15.742 G-Meter[645:20b] Acceleration value: 0.763081
2009-02-15 20:42:15.774 G-Meter[645:20b] Acceleration value: 0.526890
2009-02-15 20:42:15.827 G-Meter[645:20b] Acceleration value: 0.018169
2009-02-15 20:42:16.127 G-Meter[645:20b] Acceleration value: 0.181686
2009-02-15 20:42:16.171 G-Meter[645:20b] Acceleration value: 0.962936

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

dejo
Feb 15, 2009, 01:54 PM
They constantly change up or down but I only want the maximum value.
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).

freshking
Feb 15, 2009, 02:03 PM
My bad. Thanks for the code. Works perfectly.