 ----------------------------------------------------
 */
 
+
+/*
+Hacked virtualwire to use 8 bit timer2
+from line 510...
+
+#else // ARDUINO - hacked to timer2 http://forum.arduino.cc/index.php/topic,100371.0.html
+    // figure out prescaler value and counter match value
+    prescaler = vw_timer_calc(speed, (uint8_t)-1, &nticks);
+    if (!prescaler)
+    {
+        return; // fault
+    }
+
+    TCCR2A = 0;
+    TCCR2A = _BV(WGM21); // Turn on CTC mode / Output Compare pins disconnected
+
+    // convert prescaler index to TCCRnB prescaler bits CS00, CS01, CS02
+    TCCR2B = 0;
+    TCCR2B = prescaler; // set CS00, CS01, CS02 (other bits not needed)
+
+    // Number of ticks to count before firing interrupt
+    OCR2A = uint8_t(nticks);
+
+    // Set mask to fire interrupt when OCF0A bit is set in TIFR0
+    TIMSK2 |= _BV(OCIE2A);
+    // Enable interrupt
+#ifdef TIMSK1
+    // atmega168
+    //TIMSK1 |= _BV(OCIE1A);
+#else
+    // others
+    //TIMSK |= _BV(OCIE1A);
+#endif // TIMSK1
+
+
+
+from line 777...
+
+	#else // Assume Arduino Uno (328p or similar) hack to timer2
+		#define VW_TIMER_VECTOR TIMER2_COMPA_vect
+
+
+*/
+
+#define VW_TIMER_VECTOR TIMER2_COMPA_vect
+
 #include <util/delay.h>
 #include <avr/wdt.h>
-#include <Wire.h>
+#include <VirtualWire.h> // hacked version for timer2!!
 #include <Servo.h> 
  
 
 #define LED_DEBUG 13
-#define PIN_TX 7
+#define PIN_TX 12
 
 #define PIN_LDR_LEFT  2 // PC2
 #define PIN_LDR_RIGHT 3 // PC3

    int left = analogRead(PIN_LDR_LEFT);
    int right = analogRead(PIN_LDR_RIGHT);
    
    /*
    Serial.print(left); 
    Serial.print(':');
    Serial.print(right); 
    */
    
    int diff = left - right;
    if (abs(diff) > THRESHOLD_LDR_HORZ) {

    
    pinMode(LED_DEBUG, OUTPUT);     
    pinMode(PIN_TX, OUTPUT); 
    
    pinMode(SERVO_PIN_HORZ_POWER, OUTPUT); 
    digitalWrite(SERVO_PIN_HORZ_POWER, LOW); // low = 0n (PNP)
    
    
    //vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);      // Bits per sec
    vw_set_tx_pin(PIN_TX);

    servo_horz.attach(SERVO_PIN_HORZ, SERVO_HORZ_MIN, SERVO_HORZ_MAX);

    servo_horz.writeMicroseconds(servo_horz_pos);
    

    
}

