Reputation: 57
I have a value of Android accelerometer x axis, and on every 0.18 change of that value, the value of az should also be incrementally/decrementally changed by 5
for example:
at x=0, az=0
at x=0.18, az=5
at x=0.36, az=10
if the value of x back to 0.18, so az value must also be back to 5 (that means x and az are synchronized)
How should I implement this logic into codes?
PS: I expect "for", "if", or maybe "while" statements here
Sorry for my bad English. Thank you in advance
Upvotes: 3
Views: 126
Reputation: 4470
I presume you have some way of continually monitoring the x
value. In which case, pseudo-code:
private static final double xToAz = 5.0/0.18;
onChange(x)
{
az = xToAz * x;
az -= az%5;
}
Upvotes: 3
Reputation: 19500
Devide x with 0.18 and multiply the result with 5 to get the value of az.
az = (x / 0.18) * 5;
Upvotes: 0