Hello! I am doing a project. I have an accelerometer connected to LilyPad. And the LilyPad is connected by bluetooth to a Android device. So an Android Application is receiving the values from the accelerometer.

In the application I hace a cube (OpenGL), so I want to move the cube in order to get the same inclination. I saw this:

float roll = Math.atan2((Math.sqrt((yvalue*yvalue)+(xvalue*xvalue))),zvalue)*(180/(Math.PI));
float pitch = Math.atan2((Math.sqrt((xvalue*xvalue)+(zvalue*zvalue))),yvalue)*(180/(Math.PI));

gl.glRotatef(pitch, 0.0f, 0.0f, 1.0f); gl.glRotatef(roll, 1.0f, 0.0f, 0.0f);

Where xvalue, yvalue and zvalue are the values I receive from the acceleromter of 3 axis. But it doesnt work! The cuve rotate a little, but not good.

Can anybody help me? Thanks!!