  
 }
 
+uint8_t trigstate = LOW;
 void loop0() {
-  if (trigstate != digitalRead(_TRIGGER)) {
+  // XXX trigger on a rising edge
+  if (trigstate != digitalRead(_TRIG_PIN) && trigstate == HIGH) {
     trigcnt += 1;
     trigstate = !trigstate;
   }

  Returned value is 2s complemented 16 bit integer.
  */
int16_t read_analog(uint8_t next_chan) {
  // we really don't need any interrupts messing the timings in here up
  noInterrupts();

  // select the channel for the next read
  digitalWrite(_A0, next_chan&0x1?HIGH:LOW);
  digitalWrite(_A1, next_chan&0x2?HIGH:LOW);

  // begin a conversion
  digitalWrite(_RC, LOW);
  delayMicroseconds(1);
  digitalWrite(_RC, HIGH);

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


#define     _D6       (31)
#define     _D7       (30)

#define     _LED      (13)

#define     _TRIG_PIN (18)
#define     _TRIG_INT (5)

// *4 b/c we are sampling 4 channels. We assume each element of buf is enough
// to hold a 16bit value
#define     _BUF_SIZE (512*4)

void setup() {
  uint8_t outputs[] = {_A0, _A1, _BYTE, _RC, _LED};
  uint8_t inputs[] = {_BUSY, _D0, _D1, _D2, _D3, _D4, _D5, _D6, _D7};

  for (int idx = 0; idx < sizeof outputs; ++idx) {
    pinMode(outputs[idx], OUTPUT);
