   digitalWrite(hgmPin, HIGH);
   // set up chibi regs to turn on external P/A
   chibiRegWrite(0x4, 0xA0);
-  
-  
+
+
 }
 
 void sleep_mcu(){
   attachInterrupt(2, rtcInterrupt, FALLING);
-  delay(100);
+  digitalWrite(sonarAwakePin, LOW);
+  pinMode(sonarTriggerPin, INPUT);
+
+  pinMode(debugModePin, INPUT);
+  pinMode(burstModePin, INPUT);
+
+  delay(1000);
 
   set_sleep_mode(SLEEP_MODE_PWR_DOWN);
   sleep_radio();
   sleep_enable();        // setting up for sleep ...
-  
+
   ADCSRA &= ~(1 << ADEN);    // Disable ADC
   Serial.println("Going to sleep");
-  delay(100);
+  delay(1000);
   digitalWrite(ledPin, LOW);
+
+
+  if(digitalRead(burstModePin)==HIGH){
+    // Every 30 minutes
+    pcf.runWatchdogTimer(0b11,30);
+    Serial.println("Sleeping for 30 minutes");
+    Serial.flush();
+  }
+  else{
+    // Every 10 seconds
+    pcf.runWatchdogTimer(0b10,10);
+    Serial.println("Sleeping for 10 seconds");
+    Serial.flush();
+  }
+
+  //pcf.runWatchdogTimer(RTC_CLOCK_SOURCE, RTC_SLEEP);
+
   sleep_mode();
-
+  /* ....ZZzzzzZZzzzZZZzz....*/
   sleep_disable();
   Serial.println("Awake");
   digitalWrite(ledPin, HIGH);
+  pinMode(sonarTriggerPin, OUTPUT);
+  digitalWrite(sonarAwakePin, HIGH);
   wakeup_radio();
   ADCSRA |= (1 << ADEN); // Enable ADC
+  // Let the sonar "boot up"
+  delay(5000);
+  pinMode(debugModePin, INPUT_PULLUP);
+  pinMode(burstModePin, INPUT_PULLUP);
 }
 
 

  }


  // This is where you declare the commands for the command line.
  // The first argument is the alias you type in the command line. The second
  // argument is the name of the function that the command will jump to.
  
  chibiCmdAdd("getsaddr", cmdGetShortAddr);  // set the short address of the node
  chibiCmdAdd("setsaddr", cmdSetShortAddr);  // get the short address of the node
  chibiCmdAdd("send", cmdSend);   // send the string typed into the command line
  chibiCmdAdd("send2", cmd_tx2);  
  chibiCmdAdd("rd", cmd_reg_read);   // send the string typed into the command line
  chibiCmdAdd("wr", cmd_reg_write);   // send the string typed into the command line
  chibiCmdAdd("slr", cmdSleepRadio);
  chibiCmdAdd("slm", cmdSleepMcu);
  chibiCmdAdd("sdw", cmdSdWrite);
  chibiCmdAdd("sdr", cmdSdRead);
  chibiCmdAdd("sdc", cmdSdClear);
  chibiCmdAdd("time", cmdWriteTime);
  chibiCmdAdd("date", cmdWriteDate);
  chibiCmdAdd("rdt", cmdReadDateTime);
  chibiCmdAdd("bat", cmdVbatRead);
  chibiCmdAdd("sol", cmdVsolRead);
  
  chibiCmdAdd("tmp", cmdReadTemp);
  
  // high gain mode
  digitalWrite(hgmPin, HIGH);

  
}

/**************************************************************************/

  Serial.print("Solar voltage: "); Serial.println((float)(s/1000.0), 1);
}


/**************************************************************************/
/*!
