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


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


int PIStates[] = { 1, 1 };
int lastStates[] = { 1, 1 };
int lastTime[] = { 0, 0 };
int pelletCount[] = { 0, 0 };

#define FILENAME "PelletData.csv"
