 {
 
   if (hadRound== 1) {
-    #if NORMALPOW
+#if NORMALPOW
     Serial.println("had round");
-  #endif
+#endif
     // compare the time of the last logged or the current logged value
     // the actual calculation
-      if (beginRun==0) {
-        beginRun=time;
-      } 
-      if (lastMeasurement == 0 ){
-        lastMeasurement = time;
+    if (beginRun==0) {
+      beginRun=time;
+    } 
+    if (lastMeasurement == 0 ){
+      lastMeasurement = time;
+    }
+    curDistance = curDistance + distance;
+    //
+    //      // write to SD card
+
+    ////      // here, we can write the full, readable timestamp:
+    char output[25];
+    // length of output should be: 5 fixed, 10 time, 10 distance;
+    sprintf(output,"R:%10lu:%10lu\n",time,curDistance);
+    dataFile.write(output,25);
+    dataFile.flush();
+
+    byte reset= 0;
+#if DEBUG
+    if (ble_connected()) {
+      char temp[32];
+      sprintf(temp,"resetting:%10lu:%10lu\n",lastMeasurement,time);
+      ble_write_bytes( (unsigned char *)temp,32);
+    }
+#endif
+    if ((time-lastMeasurement)>timeBetweenRounds) {
+#if DEBUG
+      if (ble_connected()) {
+        ble_write_bytes( (unsigned char *)"reset\n",6);
       }
-      curDistance = curDistance + distance;
-//
-//      // write to SD card
-
-////      // here, we can write the full, readable timestamp:
-              char output[25];
-            // length of output should be: 5 fixed, 10 time, 10 distance;
-            sprintf(output,"R:%10lu:%10lu\n",time,curDistance);
-            dataFile.write(output,25);
-            dataFile.flush();
-
-      byte reset= 0;
-              #if DEBUG
-          if (ble_connected()) {
-                      char temp[32];
-            sprintf(temp,"resetting:%10lu:%10lu\n",lastMeasurement,time);
-             ble_write_bytes( (unsigned char *)temp,32);
-          }
-        #endif
-      if ((time-lastMeasurement)>timeBetweenRounds) {
-              #if DEBUG
-          if (ble_connected()) {
-
-
-             ble_write_bytes( (unsigned char *)"reset\n",6);
-          }
-        #endif
-          reset=1;
-          char result[37];
-          // length of output should be: 7 fixed, 10 begin, 10 time , 10 distance;
-          sprintf(result,"Run:%10lu:%10lu:%10lu\n",beginRun,time,curDistance);
-          runs.write(result,37);
-        runs.flush();
-        curDistance=distance;
-        beginRun=millis();
-      }
-        #if DEBUG
-          stroller_ble_print();
-        #endif
-          lastMeasurement = time;
-          hadRound=0;
+#endif
+      reset=1;
+      char result[37];
+      // length of output should be: 7 fixed, 10 begin, 10 time , 10 distance;
+      sprintf(result,"Run:%10lu:%10lu:%10lu\n",beginRun,time,curDistance);
+      runs.write(result,37);
+      runs.flush();
+      curDistance=distance;
+      beginRun=millis();
+    }
+#if DEBUG
+    stroller_ble_print();
+#endif
+    lastMeasurement = time;
+    hadRound=0;
 
   }
   if (ble_available() )


void setup()
{  
//  pinMode(LED, OUTPUT);

  attachInterrupt(interupt, BtnDownCB, FALLING );

  // Call the function to enable low power consumption
  #if !NORMALPOW
    ble_low_power();
  #else 
   Serial.begin(9600);
  #endif
  time =1; // init the time to 1, to make it different from 0
  // If you are using the Blend, uncomment below
  ble_set_pins(6, 7);
   ble_set_name("Stroller");

  // Init. and start BLE library.
  ble_begin();

  // prepare SD data logging!
//
  if (!SD.begin(10, 11, 12, 13)) { // important: this is custom code for the leonardo, see https://learn.adafruit.com/adafruit-data-logger-shield/for-the-mega-and-leonardo

  } 

      }
    }
  }
  //  delay(50);
#if DEBUG
  digitalWrite(LED,LOW);
#endif
  ble_do_events();  
}

