omron_binary_read.pde
int cld1Pin = 4;            // Card status pin
int rdtPin = 2;             // Data pin
int reading = 0;            // Reading status
#define BUFFER_SIZE 700
volatile int overwrite_fu = 0;
volatile int buffer[BUFFER_SIZE] = {};   // Buffer for data
volatile int i = 0;         // Buffer counter
volatile int bit = 0;       // global bit
 
void setup() {
  Serial.begin(115200);
 
  // The interrupts are key to reliable
  // reading of the clock and data feed
  attachInterrupt(0, changeBit, CHANGE);
  attachInterrupt(1, writeBit, FALLING);
}
 
void loop(){
 
  // Active when card present
  while(digitalRead(cld1Pin) == LOW){
    reading = 1;
  }
 
  // Active when read is complete
  // Reset the buffer
  if(reading == 1) {
    for (int x=0; x<BUFFER_SIZE; x++) {
      Serial.print(buffer[x]);
    }
    Serial.println("");
    Serial.println("Read finished.");
    reading = 0;
    i = 0;
  }
}
 
 
// Flips the global bit
void changeBit(){
  if (bit == 0) {
    bit = 1;
  } else {
    bit = 0;
  }
}
 
// Writes the bit to the buffer
void writeBit(){
  if (i >= BUFFER_SIZE) {
    Serial.println("buffer overflow detected, perhaps increase the buffer size? FUUUUUUUUUU!");
  } else {
    buffer[i] = bit;
    i++;
  }
}