That accelerometer is an analog device. The "standard" example codes for it, return an integer for each axis, apparently normalised to 100 representing 1g.

You mentioned that you are not using the z axis, so I assume that you have your x and y axes horizontally and your z vertical. If you have your x axis pointing "forwards" and your y axis pointing sideways, then, for very small angles of pitch and roll, the x and y readings will represent 100 x the sine of the pitch and roll axes, in radians, respectively.

Note the limitations here. That calculation will only work if the device is not actually accelerating anyway, and also not subjected to a rotational acceleration. It's going to work for tilted objects, not spinning objects. And it is not going to work for large angles of pitch and roll.

You also need to be clear on what part of your calculations require integer and floating point arithmetic. If you don't want to use floating point types, you can work around that but you need to be clear on what you are doing.

your statement that int(0.1) results in 1, seems to be wrong. Actually, to the best of my knowledge, C doesn't even have an INT( ) function. Matlab and Fortran do.... You can cast numbers to an int, like this

float f = 4.7 ;

int i = (int) f ; // the result of this is (integer) 4

but that is not actually a function call.

This is how you would calculate the pitch and roll, representing the tilt of your device in degrees, where the x and y directions are oriented forwards and sideway, and z vertical, provided that the device has no accelerations and therefore that the numbers coming from the device represent only the static effect of gravity, and that the numbers are integers normalised to 100 = 1g :

int x ; // accelerometer reading

int y ; // accelerometer reading

int z ; // accelerometer reading

void loop()

{

x= accelero.getXAccel() ;

y = accelero.getYAccel( );

float pitch_sine = ((float)x)/100.0 ; // this is the sine of the pitch angle

// Check that the sine of the pitch angle is within the legal range between -1 and 1

// If either part of this section is true, it means that the device has a substantial actual acceleration,

// or that the device is poorly calibrated.

if ( pitch_sine > 1.0 ) pitch_sine = 1.0 ;

else if ( pitch_sine < -1.0 ) pitch_sine = -1.0 ;

float pitch_radians = asin ( pitch_sine ) ; // calculates the pitch angle, in radians

float pitch_degrees = pitch_radians * 57.3 ; // convert result to degrees, multiply by 180/pi

}

For SMALL angles of pitch and roll, less than maybe about 20 degrees, you can use the approximation that the sine of the angle ( in radians ), is not very different to the angle in radians. Therefore, you could use this calculation

int x = accerelo.getXAccel( ) ; // x direction component, normalized to 100 = 1g

int pitch_degrees = x * 57 / 100 ;

This calculation uses no float math at all. However, it will overflow the arduino 16 bit int if the value of x exceeds about 55 . To be clear why this is, the product x times 57 must be less than 32767, the limit for ints.

However, this approach is only valid for the range of tilt for which sine(y) is approximately equal to y ( in radians ) , which is for angles less than about +/- 20 degrees, depending on your tolerance for "approximately". If you are using this model to measure the range of tilt for which it is appropriate, then the overflow would not be an issue.