 
 
   if (inputRight && !tripped) {
-    while (true) {
-    digitalWrite(CCWpin, HIGH);
-    if (tripped) {
-      digitalWrite(CCWpin, LOW);
+    jogMode_run(CCWpin, rightRed);
+  }
+
+  if (inputLeft && !tripped) {
+    jogMode_run(CWpin, leftRed);
+  }
+  if (green.isHit()) {
+    hallInterCount = 0;
+    loopCounter = 0;
+  }
+  if (yellow.isHit()) {
+    lcd.clear();
+  }
+  if (tripped) {
+    tripped = false;
+    digitalWrite(CCWpin, LOW);
+  }
+
+  lcd.setCursor(0,0);
+  lcd.print("Steps passed:");
+  lcd.setCursor(14,0);
+  lcd.print(hallInterCount);
+
+  lcd.setCursor(0,1);
+  lcd.print("Temp passed:");
+  lcd.setCursor(14,1);
+  lcd.print(tempHallCount);
+
+  lcd.setCursor(0,2);
+  lcd.print("delay");
+  lcd.setCursor(14,2);
+  lcd.print(jDelay);
+
+  lcd.setCursor(0,3);
+  lcd.print("loops:");
+  lcd.setCursor(14,3);
+  lcd.print(loopCounter);
+}
+
+void hallCount() {
+  time = micros();
+  hallInterCount = hallInterCount + 1;
+  tripped = true;
+  time = micros() - time;
+}
+
+int getJogDelay() {
+  // speed up the jog based on how long  a button has been held
+  if(hallInterCount <= 1) {              // init to half a second
+    jDelay = 500;
+  }
+  if(jDelay > 11) {            
+    jDelay = jDelay - jDelay/jogSlope;// nice logrythmic decrease
+  } 
+  else {
+    jDelay = 10;                     // set a 10 ms lower delay limit
+  }
+  return jDelay;
+}
+
+int pwmRamp() {
+  if (hallInterCount <=25) {
+    pwmSlope = 100;
+  }
+  if (hallInterCount <= 25) {
+    pwmSlope++;
+  }
+  return pwmSlope;
+}
+
+void jogMode_run(int direction, int button) {
+  int inputLeft = digitalRead(leftRed);
+  int inputRight = digitalRead(rightRed);
+
+  int read = digitalRead(button);
+
+  while (true) {
+    digitalWrite(direction, HIGH);
+    read = digitalRead(button);
+    loopCounter++;
+    if (!read) {
+      digitalWrite(direction, LOW);
+      jDelay = 500;
+      hallInterCount = 0;
+      break;
+    }
+    if (tripped && hallInterCount <= 16) {
+      digitalWrite(direction, LOW);
       tripped = false;
       break;
     }
-  }
-  delay(100);
+    if (hallInterCount >= 17 && !read) {
+      tripped = false;
+      jDelay = 500;
+      hallInterCount = 0;
+      break;
+    }
+  }
+
+  read = digitalRead(button);
+
+  lcd.clear();
+  getJogDelay();
+  delay(jDelay);
   tripped = false;
-  }
-  if (left_Rb.isHit()) {
-    digitalWrite(CCWpin, LOW);
-  }
-  if (green.isHit()) {
-    hallInterCount = 0;
-    loopCounter = 0;
-  }
-  if (yellow.isHit()) {
-    lcd.clear();
-  }
-  if (tripped) {
-    tripped = false;
-    digitalWrite(CCWpin, LOW);
-  }
- lcd.setCursor(0,0);
- lcd.print("Steps passed:");
- lcd.setCursor(14,0);
- lcd.print(hallInterCount);
-
- lcd.setCursor(0,1);
- lcd.print("Temp passed:");
- lcd.setCursor(14,1);
- lcd.print(tempHallCount);
-
- lcd.setCursor(0,2);
- lcd.print("isr timing:");
- lcd.setCursor(14,2);
- lcd.print(time);
-
-  lcd.setCursor(0,3);
- lcd.print("Loop count:");
- lcd.setCursor(14,3);
- lcd.print(loopCounter);
-
- loopCounter++;
-}
-
-void hallCount() {
-    time = micros();
-  hallInterCount = hallInterCount + 1;
-  tripped = true;
-   time = micros() - time;
-}
-
+}

void loop() {

   

  int inputLeft = digitalRead(leftRed);
  int inputRight = digitalRead(rightRed);

Tap left_Rb(leftRed);
Tap yellow(yellowEnter);

unsigned long loopCounter = 0; //Loop counter to refresh screen.
unsigned long lcdUpdate;
unsigned long lastLcdUpdate;
int refreshScreen = 0; //boolean counter to clear screen.
