 {
 //   detachInterrupt(InterruptId);
    unsigned long ThisIntTime = micros();
+   LstIntTime = millis();
    if (ThisIntTime < WaitInterval) return;
    WaitInterval = ThisIntTime+3000; //move the next valid interrupt out by 3 milliSeconds (the squivalent of the spindle turning @ 20K RPM )
    if (eventCounter == 1)
      {
       Start = ThisIntTime;
+      ActivIntrpt = true;
      }
    if (eventCounter == SampleCnt+1)
      {

// ================================================================


static int ScanButtons()
{
  int buttons = 0;
  int buttonPressed = Keypad.button();
  if (buttonPressed==KEYPAD_UP) buttons += 1;
  if (buttonPressed==KEYPAD_DOWN) buttons += 2;
  if (buttonPressed==KEYPAD_LEFT) buttons += 4;
  if (buttonPressed==KEYPAD_RIGHT) buttons += 8;
  if (buttonPressed==KEYPAD_SELECT) buttons += 16;
  if (buttonPressed==KEYPAD_NONE) NuInput = true;
  return buttons;
}

void UpDateSettings(int UsrInput, int mode)

LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //initialize Sansmart LCD Display
LCDKeypad Keypad;
int trgtRPM = 5000;
unsigned long LstIntTime = 0; 
unsigned long Start = 0; 
unsigned long Stop; 
unsigned long WaitInterval =0;
unsigned long startPrgm = millis()/1000; 
unsigned long now;
unsigned long QrtrSecTimeOut = millis() ;
int SampleCnt = 10; // Number Spindle Relolutions needed to make a new RPM calculation
unsigned long period;
unsigned long Maxperiod;
