 }
 
 void go(int steps, int dir) {
-  if(dir <= 0) {
-    digitalWrite(X_DIR_PIN, LOW);
-  } else {
-    digitalWrite(X_DIR_PIN, HIGH);
-  }
+  int accel_steps = 0;
+  int hold_time = 1000;
+  int accel_time = 2;
+
+
+  digitalWrite(X_DIR_PIN, dir);
+  //digitalWrite(Y_DIR_PIN, dir);
 
   for (int i = 0; i < steps; i++){    
-    int hold_time = step_time;
-    if(i==0 || i == steps-1){
-      hold_time = 800;
-    } else if (i == 1 || i == steps-2) {
-      hold_time = 750;
-    } else if (i == 2 || i == steps-3) {
-      hold_time = 600;
-    } else if (i == 3 || i == steps-4) {
-      hold_time = 500;
-    } else if (i == 4 || i == steps-5) {
-      hold_time = 400;
-    } else if (i == 5 || i == steps-6) {
-      hold_time = 300;
-    } else if (i == 6 || i == steps-7) {
-      hold_time = 200;
-    } else if (i == 7 || i == steps-8) {
-      hold_time = 100;
-    } else if (i == 8 || i == steps-9) {
-      hold_time = 70;
-    } else if (i == 9 || i == steps-10) {
-      hold_time = 50;
+    //determine pulse time
+    if(i > steps - accel_steps) {
+      //In decelleration phase
+      hold_time += accel_time;
+    } 
+    else if(hold_time > step_time) {
+      //In accelleration phase
+      hold_time -= accel_time;
+    } 
+    else if(hold_time < step_time) {
+      hold_time = step_time;
     }
+    //pulse the motor
     digitalWrite(X_STEP_PIN, HIGH);
+    //digitalWrite(Y_STEP_PIN, HIGH);
     delayMicroseconds(20);
     digitalWrite(X_STEP_PIN, LOW);
+    //digitalWrite(Y_STEP_PIN, LOW);
     delayMicroseconds((hold_time)-20);      
   }
   //digitalWrite(DISABLE_PIN, HIGH);  


const int X_STEP_PIN = 2;
const int X_DIR_PIN = 5;
const int DISABLE_PIN = 8;

/*
  With all 3 jumpers in the driver is configured to run at 1/16 microstepping
*/
const int STEPS_PER_ROTATION = 200 * 16;

int step_time = 500;
int is_active;

void setup() {
  pinMode(X_STEP_PIN, OUTPUT);
  pinMode(X_DIR_PIN, OUTPUT);
  pinMode(DISABLE_PIN, OUTPUT);
  Serial.begin(57600);
  Serial.println("RoboFoos Ready!");
  digitalWrite(X_DIR_PIN, HIGH);

    Serial.print("Running with ");
    Serial.println(step_time);
  }
  if(is_active > 0 || digitalRead(X_ENDSTOP_PIN) == HIGH) {
    digitalWrite(DISABLE_PIN, LOW);
    int x_steps = random(STEPS_PER_ROTATION/10, STEPS_PER_ROTATION * 1.5);
    go(x_steps, LOW);
    go(x_steps, HIGH);    
    digitalWrite(DISABLE_PIN, HIGH);
  } 
  else {
    digitalWrite(DISABLE_PIN, HIGH); 
  }
}


