Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java/Android: Increment Algorithm

Tags:

java

android

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

like image 646
Duriothenoob Avatar asked Jun 21 '26 08:06

Duriothenoob


1 Answers

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;
}
like image 180
Ina Avatar answered Jun 22 '26 22:06

Ina



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!