 //=======================================================================================
 
 
-void zeroplane() {
-      /////////////////////////////////////////////////////////// X LEFT RIGHT
+
+
+// START ZEROAXIS()
+void zeroaxis() {
+  /*
+      Runs each motor towards the zero switch and resets its position. Must be run at start.
+  */
+
+    ////////////////////////////////////////////////////////ZERO Z - UPDOWN
+    while (digitalRead(zZeropin) != zZeroNC) {             
+      stepperZdestPosition = stepperZdestPosition + 1;
+      while (stepperZdistanceToGo() != 0) {
+        stepperZrun();
+      }
+    }
+
+    //top most is equal to tablezsteps
+    stepperZcurrPosition = tablezsteps;
+ 
+    //moves to zero (table surface)
+    stepperZdestPosition = 0;      
+    while (stepperZdistanceToGo() != 0) {
+      stepperZrun();
+    }   
+    lastz = 0;    
+
+    /////////////////////////////////////////////////////////// X LEFT RIGHT
 
     while (digitalRead(xZeropin) != xZeroNC) {   
-      stepperXdestPosition = stepperXdestPosition - 32;
-      while (stepperXdistanceToGo() != 0) {
+      stepperXdestPosition = stepperXdestPosition - 1;
+      while (stepperXdistanceToGo() > 0) {
         stepperXrun();
       }
     }
-    
-    stepperXcurrPosition = -2000;
+    stepperXcurrPosition = 0;
+    lastx = 0;
+
     //moves to zero
     stepperXdestPosition = 0;
-    lastx = 0;
     while (stepperXdistanceToGo() != 0) {
       stepperXrun();
     }
+    lastx = 0;
+    
+
     ////////////////////////////////////////////////////////////// Y TABLE FRONT BACK
+ 
     while (digitalRead(yZeropin) != yZeroNC) {   
-      stepperYdestPosition = stepperYdestPosition + 32;
+      stepperYdestPosition = stepperYdestPosition + 1;
       while (stepperYdistanceToGo() != 0) {
         stepperYrun();
       }      
     }
+    //zero switch is on high side
+    stepperYcurrPosition = tableysteps;
+    
     //moves to 0
-    stepperYcurrPosition = tableysteps+10000;
     stepperYdestPosition = 0;
     lasty = 0;
     while (stepperYdistanceToGo() != 0) {
       stepperYrun();
     }      
-}
-
-// START ZEROAXIS()
-void zeroaxis() {
-  /*
-      Runs each motor towards the zero switch and resets its position. Must be run at start.
-  */
-
-    ////////////////////////////////////////////////////////ZERO Z - UPDOWN
-    Serial.print("{ \"log\" : \"Attempting to zero Z axis\"}");
-
-    while (digitalRead(zZeropin) != zZeroNC) {             
-      stepperZdestPosition = stepperZdestPosition + 16;
-      while (stepperZdistanceToGo() != 0) {
-        stepperZrun();
-      }
-    }
-
-    stepperZcurrPosition = tablezsteps + 6400;
- 
-    //moves to zero
-    stepperZdestPosition = 0;      
-    lastz = 0;
-    while (stepperZdistanceToGo() != 0) {
-      stepperZrun();
-    }   
-    /////////////////////////////////////////////////////////// X LEFT RIGHT
-    Serial.print("{ \"log\" : \"Attempting to zero X axis\"}");    
-    while (digitalRead(xZeropin) != xZeroNC) {   
-      stepperXdestPosition = stepperXdestPosition - 32;
-      while (stepperXdistanceToGo() != 0) {
-        stepperXrun();
-      }
-    }
-    
-    stepperXcurrPosition = -2000;
-    //moves to zero
-    stepperXdestPosition = 0;
-    lastx = 0;
-    while (stepperXdistanceToGo() != 0) {
-      stepperXrun();
-    }
-    
-    Serial.print("{ \"log\" : \"X axis zero success\"}");
-    ////////////////////////////////////////////////////////////// Y TABLE FRONT BACK
-    Serial.print("{ \"log\" : \"Attempting to zero Y axis\"}");   
-    while (digitalRead(yZeropin) != yZeroNC) {   
-      stepperYdestPosition = stepperYdestPosition + 32;
-      while (stepperYdistanceToGo() != 0) {
-        stepperYrun();
-      }      
-    }
-    //moves to 0
-    stepperYcurrPosition = tableysteps+10000;
-    stepperYdestPosition = 0;
-    lasty = 0;
-    while (stepperYdistanceToGo() != 0) {
-      stepperYrun();
-    }      
+    
     ////////////////////////////////////////////////////////////// E zero
-    Serial.print("{ \"log\" : \"Attempting to test E axis\"}");   
+
     stepperEdestPosition = 0;  //1 rotation
     while (stepperEdistanceToGo() != 0) {
         stepperErun();

        aJson.deleteItem(msg);                

        tempcounter++;
        if (tempcounter > 5) {
            thermistor();
            tempcounter = 0;
        }

double stepperEdestPosition = 0;
double stepperEtimer = 0;
int    stepperEtoggle = 0;
double stepperEspeed = 6400;


// Motor Zero switch pins
