Led luminosity based on gyro movements

Hi to all, this is the first time I write on this forum, and I'm trying to accomplish my first real Arduino prototype; I hope to find some help; if I posted on the wrong section please move this thread.

I'm trying to control the luminosity of a led based on the movement of a gyro; here is the code I have until now; it works less or more but I think am sure I have a problem in the loop. My idea is:

when I start moving the gyro the luminosity of the LED grows (it works)
if the gyro stop moving the luminosity decrease (it works) and when it reach 0 another led (red) blinks
if you move the gyro for at least 30 seconds the led start blinking (you won the match)

the first problem I see is that if I don't move the gyro the LED starts the decrease, increase process.

Any idea?

Thanks in advance

int x_zero = 0;
int y_zero = 0;
int x_val = 0;
int y_val = 0;
int movement = 0;
int luminance = 0;
unsigned long int timestamp = 0;

const int LED =11;

void setup() {

  pinMode (LED, OUTPUT);
  Serial.begin(9600);
  x_zero = smoothRead(0);
  y_zero = smoothRead(1);
  timestamp = millis();
}

void loop() {
  x_val = smoothRead(0)-x_zero;
  y_val = smoothRead(1)-y_zero;


  if (abs(abs(x_val) - abs(y_val)) > 30) {
    if  (abs(x_val) > abs(y_val))  {
      movement++;
      analogWrite(LED,luminance++); 
    }

    else {    
      movement--;
      analogWrite(LED,luminance--);

    }

    if (movement > 255) movement = 255;
  }

  else {
    movement--;
    analogWrite(LED,luminance--);
  }

  Serial.println(movement);
  analogWrite(9,movement);
  //analogWrite(10,movement);

  //  if ((millis() - timestamp) > 500) {
  //    timestamp = millis();
  //    movement = movement - 10;
  //    if (movement < 0) movement = 0;  
  //  }

  if (luminance > 255) luminance = 255;

  //  if ((millis() - timestamp) > 500) {
  //    timestamp = millis();
  //    luminance = luminance - 100;
  //    if (luminance < 0) luminance = 0;  
  //  }

}



int smoothRead(int channel) {
  int val = 0;
  for (int i = 0; i < 100; i++) {
    val = val + analogRead(channel);
  }
  val = val / 10;
  return val;
}
int val = 0;
  for (int i = 0; i < 100; i++) {

I don't know what your range of values is, but there's a potential problem right off.
If your typical reading is over 327, your "val" is going to overflow.
"val" should be a "long"