Alright so this problem has been bugging me for most of the night tho I just realized what exactly it was. Basically, multiplying a number by itself or any other number is not working. Take a look at the output Im getting
Code:
long yaw, pitch, roll; //three axes
int joy_x_axis, joy_y_axis, accel_x_axis, accel_y_axis, accel_z_axis;
//in the loop
pitch=sq(accel_x_axis);
roll=sq(accel_x_axis)+sq(accel_y_axis)+sq(accel_z_axis);
yaw=accel_x_axis*accel_y_axis;
Serial<<accel_x_axis<<"\t"<<accel_y_axis<<"\t"<<accel_z_axis<<"\t";
Serial<<pitch<<"\t\t"<<roll<<"\t\t"<<yaw<<endl;
and Im getting the output
733 532 630 13001 -27971 -3260
736 533 633 17408 -18710 -928
736 533 633 17408 -18710 -928
733 532 632 13001 -25447 -3260
if you take a calculator you will see that 733^2=537289, 733^2+532^2+632^2=1219737, and 733*532=389956.
Why isnt anything coming out right? Nothing should have floating point problems. Im sure this is something Ill hit myself in the morning but for now its driving me mad. Please help!
Yes this is all from a nunchuck example.