 //#define LED_D0       15
 
 //fudged for 1 bit reader (bit 7 only)
-#define ALL_PAPER  0x80 // high for paper
-#define ALL_HOLES  0x00 // low for hole
-
-#define REG_PAPER 1 // high for paper 
-#define REG_HOLE  0 // low for hole
+#define ALL_PAPER  (PAPER*0xFF)
+#define ALL_HOLES  (HOLE *0xFF)
+
+#define REG_PAPER PAPER 
+#define REG_HOLE  HOLE
 
 // Set to 8, will only read IN phase
 // Set to 16, will read and collect OUT phase also

  sendCardReport(REPORT_OK_BOOT, NULL, 0);
}

byte freg;
byte now;

void loop()
{  
  //readPins
  freg = (digitalRead(REG) ? REG_PAPER : REG_HOLE);
  now  = (digitalRead(D7)  ? ALL_PAPER : ALL_HOLES);

  // Show live diagnostics on LEDs
  writeLEDs(freg, now);
}

void stuff()
{
#if defined(CFGEN_SEND_ADC_REPORTS)
  if (now != sticky)
  {
    Serial.write(':');
    Serial.write(REPORT_OK_ADC);
    for (int i=8; i>=0; i--)
    {
      //in decimal ADC values are 10 bits (3 nybbles)
      Serial.print(adc[i]);
      Serial.print(" ");
    }
    Serial.println();
  }
#endif

  
  // crank round the acquisition state machine
  switch (state)
  {
    case STATE_NOCARD:
      // stay here while freg=hole and data=all holes (card removed)
      if ((freg == REG_HOLE) || now == ALL_HOLES)
      { // at least one sensor has seen paper
        state = STATE_INSERTING;
        //Serial.println(state);
      } 
    break;
    

      if ((freg == REG_HOLE) && (now == ALL_HOLES))
      {
        state = STATE_REMOVING;
      }
      else
      { // wait for any data to start appearing (at least one hole)
        if ((freg == REG_HOLE) || (now != ALL_PAPER))
        {
          sticky  = ~now; // 0=>hole, so we want to set bits for holes
          state   = STATE_IN_ROW;
        }
      }
    break;
