     // doesn't work as well at low speed and we don't the bobbin to run ahead of
     // the flyer. So at the low end we start raising the delay toward max regardless
     // of what it's actually set to.
-    delayBetweenMotorUpdates = map(absoluteCurrentSpeed, minimumSpeed, startOfStopDamping, maximumDelay, delayBetweenMotorUpdates);
+    newDelayBetweenMotorUpdates = map(absoluteCurrentSpeed, minimumSpeed, startOfStopDamping, maximumDelay, newDelayBetweenMotorUpdates);
+  }
+
+  if (newDelayBetweenMotorUpdates != delayBetweenMotorUpdates)
+  {
+    delayBetweenMotorUpdates = newDelayBetweenMotorUpdates;
+    motorUpdateTask.setInterval(delayBetweenMotorUpdates);
   }
 }
 
 void SetMotorState()
 {
-  unsigned long now = millis();
-  unsigned int timeSinceLastMotorUpdate = now - lastMotorUpdateTime;
-
-  if (timeSinceLastMotorUpdate > delayBetweenMotorUpdates)
-  {
-    lastMotorUpdateTime = now;
-
-    if (currentSpeed == 0 && currentDirection != targetDirection)
-    {
-      // We're at zero speed and want to switch directions.   
-      digitalWrite(directionOutPin, targetDirection);
-      currentDirection = targetDirection;
-      UpdateDirectionDisplay();
-      
-      // We don't want to actually start moving the other direction,
-      // wait for the user to hit the power button again
-      powerEnabled = false;
-    }
+  if (currentSpeed == 0 && currentDirection != targetDirection)
+  {
+    // We're at zero speed and want to switch directions.   
+    digitalWrite(directionOutPin, targetDirection);
+    currentDirection = targetDirection;
+    UpdateDirectionDisplay();
     
-    currentSpeed += SlewToward(currentSpeed, targetSpeed);
-    analogWrite(speedOutPin, abs(currentSpeed));
-  }           
+    // We don't want to actually start moving the other direction,
+    // wait for the user to hit the power button again
+    powerEnabled = false;
+  }
+  
+  currentSpeed += SlewToward(currentSpeed, targetSpeed);
+  analogWrite(speedOutPin, abs(currentSpeed));
 }
 
 boolean CanChangePowerState()

    targetSpeed = 0;
  }

  delayBetweenMotorUpdates = ReadPotentiometer(rateOfSpeedChangeInPin);
  delayBetweenMotorUpdates = map(delayBetweenMotorUpdates, 0, potentiometerCeiling, minimumDelay, maximumDelay);
  int absoluteCurrentSpeed = abs(currentSpeed);
  if (absoluteCurrentSpeed > abs(targetSpeed) && absoluteCurrentSpeed < startOfStopDamping)
  {

int targetSpeed = 0;
int currentSpeed = 0;
int delayBetweenMotorUpdates = 15;
boolean powerEnabled = false;
int targetDirection = CLOCKWISE;
int currentDirection = CLOCKWISE;
volatile int motorTicks = 0;
unsigned long secondsOfOperation = 0;
uint32_t* nextClockBufferLocation = 0;
boolean showDebugDisplay = false;
unsigned long lastDisplayTime = 0;

Thread motorUpdateTask = Thread();
Thread displayUpdateTask = Thread();
Thread clockUpdateTask = Thread();
ThreadController taskController = ThreadController();

void setup()
{  
