Richard as already suggested a good solution.
Using another approach you may decide to move the ball only if the tilt is decisively oriented into one of the allowed directions, discarding movements in the diagonal 'zone'.
The (squared, for semplicity) relative components of the tilt are:
double rax2 = ((double)AccX*AccX/(AccX*AccX+AccY*AccY);
double ray2 = ((double)AccY*AccY/(AccX*AccX+AccY*AccY);
suppose you use a
30°
degrees angle to discriminate, then:
if rax2 >= 0.75
then you choose x
movement.- if
ray2 >= 0.75
then you choose y
movement. - if both
rax2 < 0.75
and ray2 < 0.75
then you choose no movement.