Arduino infrared problems

Ah, finally I got everything to work properly. I decided to dump the Tivo remote for a universal remote, setting it up for a Sony TV like the parallax guide recommended. After switching to the Sony protocol everything fell into place and it works beautifully. I don't know what unholy things the Tivo remote has to do to get its signal across.

Pins:
-2 and 3 of the IR receiver are in GND and +5 respectively
-1 of the IR receiver is connected through a 220-ohm resistor to pin 2 of the Arduino
-A green led is placed across pin 13 and GND on the Arduino to show when it is waiting for data

A quick summary of the Sony TV protocol:
-The whole set is 13 pulses long
-The pulses are only measured while low (I'm sure there's a cool word for that but I don't know it)
-The first pulse, the start pulse, lasts about 2.4 ms (2400 microseconds)
-The following pulses are 1.2 ms (1200 microseconds) for a 1, 0.6 ms (600 microseconds) for a 0
-Each data pulse is about 0.3 ms (300 microseconds) apart
-Every set of 13 pulses is about 20-30 ms apart from each other, repeating when a button is held down

The code below will watch for a 13 pulse set and returns the set's integer equivalent, different for every button on the remote. If you want to try your own TV code you can always set the debug flag to 1 and see all of the pretty microsecond measurements.

int ir_pin = 2;                        //Sensor pin 1 wired through a 220 ohm resistor
int led_pin = 13;                      //"Ready to Recieve" flag, not needed but nice
int debug = 0;                         //Serial connection must be started to debug
int start_bit = 2000;                  //Start bit threshold (Microseconds)
int bin_1 = 1000;                      //Binary 1 threshold (Microseconds)
int bin_0 = 400;                       //Binary 0 threshold (Microseconds)

  
void setup() {
  pinMode(led_pin, OUTPUT);            //This shows when we're ready to recieve
  pinMode(ir_pin, INPUT);
  digitalWrite(led_pin, LOW);          //not ready yet
  Serial.begin(9600);
}

void loop() {
  int key = getIRKey();                //Fetch the key
  Serial.print("Key Recieved: ");      
  Serial.println(key);                
}


int getIRKey() {
  int data[12];
  digitalWrite(led_pin, HIGH);         //Ok, i'm ready to recieve
  while(pulseIn(ir_pin, LOW) < 2200) { //Wait for a start bit
  }
  data[0] = pulseIn(ir_pin, LOW);      //Start measuring bits, I only want low pulses
  data[1] = pulseIn(ir_pin, LOW);
  data[2] = pulseIn(ir_pin, LOW);
  data[3] = pulseIn(ir_pin, LOW);
  data[4] = pulseIn(ir_pin, LOW);
  data[5] = pulseIn(ir_pin, LOW);
  data[6] = pulseIn(ir_pin, LOW);
  data[7] = pulseIn(ir_pin, LOW);
  data[8] = pulseIn(ir_pin, LOW);
  data[9] = pulseIn(ir_pin, LOW);
  data[10] = pulseIn(ir_pin, LOW);
  data[11] = pulseIn(ir_pin, LOW);
  digitalWrite(led_pin, LOW);
  
  if(debug == 1) {
    Serial.println("-----");
  }
  for(int i=0;i<11;i++) {              //Parse them
    if (debug == 1) {
        Serial.println(data[i]);
    }             
    if(data[i] > bin_1) {              //is it a 1?
      data[i] = 1;
    }  else {
      if(data[i] > bin_0) {            //is it a 0?
        data[i] = 0;
      } else {
       data[i] = 2;                    //Flag the data as invalid; I don't know what it is!
      }
    }
  }
  
  for(int i=0;i<11;i++) {              //Pre-check data for errors
    if(data[i] > 1) {                 
      return -1;                       //Return -1 on invalid data
    }
  }
  
  int result = 0;  
  int seed = 1;                                      
  for(int i=0;i<11;i++) {              //Convert bits to integer
    if(data[i] == 1) {
      result += seed;
    }
    seed = seed * 2;
  }
  return result;                       //Return key number
}

Now all I have to do is figure out what to do with it....