  ***************************************************/
 void enterSleep(void)
 {
+//      Serial.println("Going to sleep");
   
   /* Setup pin2 as an interrupt and attach handler. */
+   if (digitalRead(2)==HIGH){
   sleep_enable();
+
   attachInterrupt(0, countRPM, LOW);
-  delay(100);
+    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+//  delay(100);
+//  cli();
+//  sleep_bod_disable();
+//sei();
   
-  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+
   
   
-  sleep_mode();
+  sleep_cpu();
   
   /* The program will continue from here. */
   
   /* First thing to do is disable sleep. */
   sleep_disable(); 
+   } else {
+//     Serial.println("not yet going to sleep"); 
+   }
 }
 
 

void loop()
{
  if (hadRound==1) {
   distanceToDate=distanceToDate+distance;
  Serial.print("Distance is now: ");
  Serial.print(distanceToDate);
  Serial.print(" at  ");
  Serial.println(millis());
  hadRound=0;
  delay(100);
  } 
    delay(100);
      Serial.print(millis());

      Serial.println(" going back to sleep");
    enterSleep();
}

 ***************************************************/
ISR(WDT_vect)
{
//  Serial.print(millis());
//  Serial.println(" Watchdog overrun");
  Serial.println(" ");
  Serial.print("Distance: ");
  Serial.println(distanceToDate);
}


