       digitalWrite(j, LOW);
       value = analogRead(i);   // ignore first reading
       value = analogRead(i);
-      if (value < 100) {
+      if (value < 100 && value > 0) {
         GSLC_DEBUG_PRINT(" Detected: (A%u, D%u) = %u\n", (i - A0), j, value);
         if (found < 2) {
           Apins[found] = i;
           Dpins[found] = j;
           Values[found] = value;
-          found++;
         }
+        found++;
       }
       pinMode(j, INPUT_PULLUP);
     }
-  }
+    pinMode(i, INPUT_PULLUP);
+  }
+
   if (found == 2) {
     if (Values[0] < Values[1]) {
       nPinXm = Apins[0];


  DrawBackground();

  bool m_bDetectPinsOk = DetectPins();
}

void loop()

  int nPinYm = -1;

  int i, j, value, Apins[2], Dpins[2], Values[2], found = 0;
  bool bRet = false;

  GSLC_DEBUG_PRINT("Making all control and bus pins INPUT_PULLUP\n", "");
  GSLC_DEBUG_PRINT("Typical 30k Analog pullup with corresponding pin\n", "");
