02/07/15

Dependencies:   mbed

Dependents:   TabbedGUIMbed

Revision:
56:bf08d9e50ccc
Parent:
53:10f4f519ba69
Child:
57:f94834892570
--- a/Calculate.cpp	Thu Jul 16 14:42:29 2015 +0000
+++ b/Calculate.cpp	Tue Jul 28 14:40:26 2015 +0000
@@ -15,7 +15,8 @@
  
 //c++ variables
     time_t sensor_time ;                            //time at which sensor is broken
-    int timeDiff;                          //time between 2 sensors - not used right now   
+    Timer t;
+    double timeDiff;                          //time between 2 sensors - not used right now   
     float speed;
     int times[20];                                //array the size of #pins
     double speeds[20];                                //array of speeds     
@@ -32,25 +33,33 @@
     {
         while(!sensor[i]) 
         {
-            if(sensor[i + 1]) {
+            if(sensor[i + 1])
+             {
+                printf("it skipped a sensor");
                 sensor_time = time(NULL); 
                 i++; 
+                
                 }                                                         //error checking incase next one is done
         }
-        sensor_time = time(NULL);                                                //gets current time
-        pc.printf("\n sensor %d : %d \t", i,sensor_time);  
-        times[i] = sensor_time;                                                 //adds sensor times to array for logging.
-        if ( i > 0) {                                                       //to ensure it is not the first one
-             timeDiff  = difftime(times[i], times[i-1]);                    //calculates the time difference
-             pc.printf(" timediff: %d s \t", timeDiff); 
-             speed = distance / timeDiff;
-             pc.printf(" speed : %f m/s ", speed); 
-             speeds[i] = speed;
+       // sensor_time = time(NULL);                                                //gets current time
+        t.start();
+       // pc.printf("\n sensor %d : %d \t", i,sensor_time);  
+       // times[i] = sensor_time;                                                 //adds sensor times to array for logging.
+       timeDiff =  t.read();
+            t.reset();
+                 pc.printf(" timediff: %lf s \t", timeDiff); 
+        if ( i > 0) 
+        {                                                       //to ensure it is not the first one
+             //    timeDiff  = difftime(times[i], times[i-1]);                    //calculates the time difference
+             //t.stop();
+                 speed = distance / timeDiff;
+                 pc.printf(" speed : %f m/s ", speed); 
+                 speeds[i] = speed;
         }
         i++;
     } 
       pc.printf(" \n Calculate completed \n");                                      //alert to let user know it completed
-      printArray(speeds, times, NoOfPins);
+     // printArray(speeds, times, NoOfPins);
   
 }