 // ================================================================
 void loop() 
 {
-  //int UsrInput = 0;
+ 
   int stopCnt = 0;
   bool UpdtDis = false;
+  chkBtns = true;
   unsigned long CurPrdTime;
   lcd.setCursor(0,1);
   lcd.print("Speed Cntl Ready");


bool ScanButtons()
{
  if (millis()-QrtrSecTimeOut >250){
    QrtrSecTimeOut = millis();
    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;
    LoopCounter = LoopCounter + 1;
    UpDateSettings(buttons, Mode);
    return true;
  }
  else return false;
}

void UpDateSettings(int UsrInput, int mode)
{
   if (UsrInput !=0)
    {
      if(UsrInput == 1 || UsrInput == 2) //[Display Up or Down Button]  Speed, $
       {
//         if (mode == 3)
//          {
//           if(UsrInput == 1 )
//            {
//             if (BackLight <7)
//              {
//               BackLight = BackLight+1;
//              }
//             else
//              {
//               BackLight = 1;
//              }
//            }
//           else
//            {
//             if (BackLight >1)
//              {
//               BackLight = BackLight-1;
//              }
//             else
//              {
//               BackLight = 7;
//              }
//            }
//           //setBacklightColour (BackLight) ;
//          }
//         else
          {
           NewTrgtVal = true;
           if(UsrInput == 1 )
            {
             if (trgtRPM <10000)
              {
               trgtRPM = trgtRPM+200;
              }
            }
           else
            {
             if (trgtRPM >1500)
              {
                trgtRPM = trgtRPM-200;
              }
            }
          }
       }
      if((UsrInput == 4 || UsrInput == 8) && NuInput == true) //[Display Left o$
       {
//        Serial1.print("NuInput %s\n", NuInput ? "true" : "false");
        if (Mode == 3){ //user is leaving Scope mode so restore Display
          lcd.setCursor(0,0);
          lcd.clear();
          sprintf (buf,"Trgt RPM: %d", trgtRPM);
          lcd.print(buf);
        }


        NuInput = false;
        if (UsrInput == 4)
         {
           Mode = Mode +1;
           if (Mode == 8)
            {
              Mode = 3;
              //Mode = 4;
            }
         }
        else
         {
           Mode = Mode- 1;
           if (Mode == 2)
            {
              Mode = 7;
            }

         }
        //setBacklightColour (BackLight);
        if (Mode == 4) LoadBarGraphFont();//user just selected bargraph mode; load custom characters to support
       }
      if (UsrInput ==16)
       {
          ExitNow = true;
       }
    }
}



bool ExitNow = false;
bool NuInput = true;
bool ActivIntrpt = false;
bool chkBtns = true;
//char *intFlgStat;
//int ThrtlLpCnt= 0;
//int Startup = 0; // Locks out pid calcs on startup to give the default throttle setting a chance to take effect before correcting it
