 void checkLimitSwitch() {
   int hardLimit = digitalRead(HARDLIMITPIN);
   if (hardLimit==1) {
-    go(0);
-    goalSpeed = 0;
+    if (currentSpeed > 0) {
+      go(0);
+      goalSpeed = 0;
+    }
+    stepperpos = 0;
+  }
+}
+
+void checkPositionLimits() {
+  if (stepperpos >= MAX_POSITION * STEPS_PER_CM) {
+    if (currentSpeed < 0) {
+      go(0);
+      goalSpeed = 0;
+    }
   }
 }
 


// physical:
const float WHEEL_RADIUS = (2.0 + 0.125) * 2.54; // 2 inch wheel + 1/8" grommet, in cm





    // reset the timer
    updateTime = now;
    
  } // end if
  
  updateSpeed(elapsed);
  checkLimitSwitch();
  checkPositionLimits();
  
  // check for incoming messages 
  etherOSC.listen();
