         // switch to next profile step
         if (driveMillis >= accelProfile[accelProfileIdx].maxMillis) {
           driveMillis = 0;
+          accelProfileIdx++;
 
           // end-stop not reached at end of profile, someone might be in the way
-          if (accelProfile[++accelProfileIdx].maxMillis == 0) {
+          if (accelProfile[accelProfileIdx].maxMillis == 0) {
             motorFree();
             debug(currentMillis, F("End of profile - door blocked\r\n"));
             debug(currentMillis, F("Total ms: "));

  // 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);
/*
  *swDebounce = ((*swDebounce << 1) | digitalRead(swPin)) & 0x1FFF; // 13-bit debounce
*/
}

//__attribute__((always_inline))

#include <WS2812.h>

// MAXPIX+EXTRAPIX must fit into uint8_t
#define MAXPIX 20  // LED stripe length
#define EXTRAPIX 3 // animation buffer, read window moves back and forth EXTRAPIX pixels

// WS2812 output
const int ledPin = 11;
