 }
 
 //__attribute__((always_inline))
-inline void debounce(const int swPin, bool *const swVal, uint16_t *const swDebounce) {
+inline void debounce(const int swPin, bool *const swVal, bool *const swDeglitch, uint16_t *const swDebounce) {
   // similiar to what digitalRead() does, assumes that swPin has no timer output assigned
   // this still leads to several indirect lookups per sample. direct PINx access might be faster
-  debounce(portInputRegister(digitalPinToPort(swPin)), digitalPinToBitMask(swPin), swVal, swDebounce);
+  debounce(portInputRegister(digitalPinToPort(swPin)), digitalPinToBitMask(swPin), swVal, swDeglitch, swDebounce);
 }
 
 //__attribute__((always_inline))
-inline void debounce(const volatile uint8_t *const port, const uint8_t pinMask, bool *const swVal, uint16_t *const swDebounce) {
+inline void debounce(const volatile uint8_t *const port, const uint8_t pinMask, bool *const swVal, bool *const swDeglitch, uint16_t *const swDebounce) {
   // NB: interference near multiples of 1/interval could cause spurious edges
   *swDebounce = ((*swDebounce << 1) | ((*port & pinMask)?(1):(0))) & 0x1FFF; // 13-bit debounce
-  if (*swDebounce == 0x1000) { // edge HIGH -> 12xLOW
-    *swVal = LOW;
-  } else if (*swDebounce == 0x0FFF) { // edge LOW -> 12xHIGH
-    *swVal = HIGH;
+
+  if (*swDebounce == 0x1000 && *swDeglitch == HIGH) { // edge HIGH -> 12xLOW
+    *swVal = *swDeglitch = LOW;
+  } else if (*swDebounce == 0x0FFF && *swDeglitch == LOW) { // edge LOW -> 12xHIGH
+    *swVal = *swDeglitch = HIGH;
   }
 }
 

  LED.sync();

  // initialize debounce registers, assume steady state
  swFrontDebounce = (swFront = digitalRead(switchFront)) * 0xFFFF;
  swBackDebounce = (swBack = digitalRead(switchBack)) * 0xFFFF;
  swTriggerDebounce = (swTrigger = digitalRead(switchTrigger)) * 0xFFFF;

  Serial.print(F("Door status: "));


        motorFree();
        setLeds1(red, ledSolid);
        doorState = doorBlocked;
        swTrigger = HIGH;
        break;
      }

