  */
 
 // Adding _ prefix b/c arduino api uses some of these names otherwise
-#define     _A0       (22)
-#define     _A1       (23)
+#define     _A0       (22)  // PB3
+#define     _A1       (23)  // PB4
 #define     _BYTE     (24)
 #define     _RC       (25)
 #define     _BUSY     (26)
 
+// these pins map to PORTC
 #define     _D0       (37)
 #define     _D1       (36)
 #define     _D2       (35)


  wait_busy();

  // set the next channel to be read to 0
  read_analog(0);

  Serial.begin(19200);
  Serial.println("Ready");
}


  // wait for busy to go high
  wait_busy();

  // pre-select the high byte for reading
  digitalWrite(_BYTE, LOW);
  delayMicroseconds(1);

  // use port manipulation to read the data pins. Note that our pinmapping
  // is such that port C maps exactly onto the parallel output from the
  // ADS7825.
  uint8_t hbyte = PINC;

  // now for the low byte
  digitalWrite(_BYTE, HIGH);
  delayMicroseconds(1);

  uint8_t lbyte = PINC;

  interrupts();

  return (hbyte<<8 | lbyte);
}

uint8_t trigcnt = 0;
uint8_t trigstate = LOW;
int16_t cnt = 0;

void loop() {
  loop0();
}

int16_t buf[4];

void loop1() {
  buf[0] = read_analog(1);
  buf[1] = read_analog(2);
  buf[2] = read_analog(3);
  buf[3] = read_analog(0);
  delay(10);
  Serial.print(cnt);
  Serial.print(" ");
  Serial.print(buf[0]);
  Serial.print(" ");
  Serial.print(buf[1]);
  Serial.print(" ");
  Serial.print(buf[2]);
  Serial.print(" ");
  Serial.print(buf[3]);
  Serial.println();
  cnt += 1;
 
}

void loop0() {
  if (trigstate != digitalRead(_TRIGGER)) {
    trigcnt += 1;
    trigstate = !trigstate;
  }

  if (trigcnt >= 10) {
    trigcnt = 0;
    buf[0] = read_analog(1);
    buf[1] = read_analog(2);
    buf[2] = read_analog(3);
    buf[3] = read_analog(0);

    Serial.print(cnt);
    Serial.print(" ");
    Serial.print(buf[0]);
    Serial.print(" ");
    Serial.print(buf[1]);
    Serial.print(" ");
    Serial.print(buf[2]);
    Serial.print(" ");
    Serial.print(buf[3]);
    Serial.println();
    cnt += 1;
  }
}
