 
 void initPWM()
 {
-  // Fast PWM on timer 2 
+  // Fast PWM on timer 1 
   // PB1 ONLY (non inverting)
   TCCR1 = (1 << PWM1A) | (1 << COM1A1) | (0 << COM1A0) | (1 << CTC1) | (1 << CS10);
   setPwm(pwm_val);
 }
 
+/**
+ * Watchdog for while awake to ensure things are ticking over.
+ */
+void watchdog_setup()
+{
+  // Clear any previous watchdog interupt
+  MCUSR = 0;
+
+  
+  wdt_enable(WDTO_8S);
+  wdt_reset();
+}
+
+void goToSleep()
+{
+
+  // Turn off the RF receiver
+  digitalWrite(RF_POWER_PIN, LOW);
+  
+  
+  cli();
+  
+  // disable ADC
+  //ADCSRA = 0;
+  
+  set_sleep_mode(SLEEP_MODE_IDLE);
+
+
+  //power_all_disable();  // power off ADC, Timer 0 and 1, serial interface
+  
+  
+  // Power-down unused stuff - keep timer1 running for the pwm
+  // off - timer0, USI, ADC
+  PRR = (0 << PRTIM0) | (1 << PRTIM0) | (1 << PRUSI) | (1 << PRADC); 
+  
+  sleep_enable();
+  sei();
+  
+  // turn off brown-out enable in software
+  //MCUCR = (1 << BODS) | (1 << BODSE); // turn on brown-out enable select
+  //MCUCR = (1 << BODS) | (0 << BODSE); // this must be done within 4 clock cycles of above
+  //MCUCR = bit (BODS) | bit (BODSE);  // turn on brown-out enable select
+  //MCUCR = bit (BODS);        // this must be done within 4 clock cycles of above
+  sleep_cpu();              // sleep within 3 clock cycles of above
+
+                              
+  sleep_disable();  
+  MCUSR = 0; // clear the reset register 
+  
+  
+  //power_all_enable();    // power everything back on
+  // Turn timer0 back on
+  PRR = (0 << PRTIM0) | (0 << PRTIM0) | (1 << PRUSI) | (1 << PRADC);
+
+  // turn on the RF receiver
+  digitalWrite(RF_POWER_PIN, HIGH);
+  
+} 


#define VW_MAX_MESSAGE_LEN 40 // Same as solar/sensor
#define VW_RX_PIN 2

SoftwareSerial mySerial(SERIAL_RX_PIN, SERIAL_TX_PIN); // RX, TX

const byte debug_led = 0;

byte pwm_val = 30;


void setup()
{

  pinMode(debug_led, OUTPUT);    
  
  pinMode(1, OUTPUT); // PWM on timer1
  initPWM();

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Setup");

    
  }

  
  _delay_ms(500); // VERY TEMP
}

void setPwm(byte val)
