 int lastTiltState = HIGH; // the previous reading from the input pin
 
 long lastDebounceTime = 0;  // the last time the output pin was toggled
-long debounceDelay = 50;    // the debounce time; increase if the output flickers
+long debounceDelay = 10;    // the debounce time; increase if the output flickers
 
 SignalProcessing input(input_pin, filter_size);
 

    // than the debounce delay, so take it as the actual current state:
    
    // if the button state has changed:
    if (sensorReading != tiltState)
    {
      tiltState = sensorReading;
      
      // if the sensor reading is low
      if (sensorReading == LOW) {
        // make the status of the output_pin to go on:
        ledState = HIGH;   
        analogWrite(output_pin, input_val/4);
          
        // dalay the LED on for one second:
        delay(500);
      }
      // otherwise if it is high
      else if (sensorReading == HIGH){
        // make the status of the output_pin to stay off:
        ledState = LOW;
        analogWrite(output_pin, 0);
      }
    }
   }
   
  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  lastTiltState = sensorReading; 
  
  // delay to avoid overloading the serial port buffer:
  delay(100);
}                                                                                                                                                                                                                                                                                            

}

void loop() {
  input_val = cutAndMap(input.filteredAnalogRead(AVERAGE), 50, 975, 0, 1023);

  // read sensor
  sensorReading = digitalRead(tilt_sensor);
  
  if (sensorReading != lastTiltState) {
