 
     logData();
     updateDisplay();
-    justMoved[inputNum] = false;
+    lastTime[inputNum] = 0;
   }
   else if (PIStates[inputNum] == 1) {
     //need to replace pellet
-    if (!justMoved[inputNum]) {
+    if (lastTime[inputNum] >= 8) {
       Serial.print(F("Replacing pellet #"));
       Serial.print(String(inputNum + 1));
       Serial.println(F("..."));
       moveMotor(inputNum);
-      justMoved[inputNum] = true;
+      lastTime[inputNum] = 6;
+      delay(200);
     }
     else
-    { delay(500); justMoved[inputNum] = false; }
+    { delay(500); lastTime[inputNum] += 1; }
   }
   
   else if (PIStates[inputNum] == 0 & PIStates[inputNum] != lastStates[inputNum]) {


int PIStates[] = { 1, 1 };
int lastStates[] = { 1, 1 };
bool justMoved[] = { true, true };
int pelletCount[] = { 0, 0 };

#define FILENAME "PelletData.csv"

    Serial.print(F("Pellet #"));
    Serial.print(String(inputNum + 1));
    Serial.println(F(" replaced"));
    lastTime[inputNum] = 0;
  }
  
  else  { //if PIStates == 0
    //pellet still there, do nothing
    lastStates[inputNum] = PIStates[inputNum];
    lastTime[inputNum] = 0;
    return false;
  }
  lastStates[inputNum] = PIStates[inputNum];
