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

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

void setup()
{  

    // 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.
    newDelayBetweenMotorUpdates = map(absoluteCurrentSpeed, minimumSpeed, startOfStopDamping, maximumDelay, newDelayBetweenMotorUpdates);
  }

  if (newDelayBetweenMotorUpdates != delayBetweenMotorUpdates)
  {
    delayBetweenMotorUpdates = newDelayBetweenMotorUpdates;
    motorUpdateTask.setInterval(delayBetweenMotorUpdates);
  }
}

void SetMotorState()
{
  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;
  }
  
  currentSpeed += SlewToward(currentSpeed, targetSpeed);
  analogWrite(speedOutPin, abs(currentSpeed));
}

boolean CanChangePowerState()
