ADXL345 - remove shaking measurements

Hi,

I made angle meter with ADXL345, measuring angle using X Axis.
In this example, as you can see, when angle is higher that desired, left or right LED is turning ON.
It is working perfect when I lean it to the "left" and "right" slowly, but when I'm shaking device "up" and "down" ( Y axis), LEDs are turning on also. So, I would like to remove this "side effect" ie to avoid impact of Y axis on my measurements.

Here is sample code that I used:

#include <Wire.h>
#include <ADXL345.h>
#include <EEPROM.h>

ADXL345 adxl;

int x, y, z;
int rawX, rawY, rawZ;
float X, Y, Z;
float rollDeg1;
int ledLeft = 3;
int ledRight = 4;
//int adress = 0;


void setup() {
  Serial.begin(9600);
  adxl.powerOn();
  pinMode (ledLeft, OUTPUT);
  pinMode (ledRight, OUTPUT);
}

void loop() {

  adxl.readAccel(&x, &y, &z);
  rawX = x - 7;
  rawY = y - 6;
  rawZ = z + 10;

  X = rawX / 256.00; 
//  Y = rawY / 256.00; 
//  Z = rawZ / 256.00; 

  rollDeg1 = 180 * (atan(Y / sqrt(X * X + Z * Z))) / PI;

  if (rollDeg1 >= 45) {
    digitalWrite (ledRight, HIGH);
    delay(50);
    digitalWrite (ledRight, LOW);
  }
  if (rollDeg1 <= -45) {
    digitalWrite (ledLeft, HIGH);
    delay(50);
    digitalWrite (ledLeft, LOW);
  }
}

Thanks in advance.

You seem to have a misaligned X axis. Calibrate your sensor and translate the axes properly.

Y and Z are not defined in the following equation, so the results will be nonsensical.

 rollDeg1 = 180 * (atan(Y / sqrt(X * X + Z * Z))) / PI;

This does nothing useful:

  rawY = y - 6;
  rawZ = z + 10;