02/07/15

Dependencies:   mbed

Dependents:   TabbedGUIMbed

Revision:
44:3b45ec49bc44
Parent:
39:3527578e78dd
Child:
47:1dc3b5f7bf4a
diff -r 8e154016dd89 -r 3b45ec49bc44 Calculate.cpp
--- a/Calculate.cpp	Wed Jul 08 15:16:26 2015 +0000
+++ b/Calculate.cpp	Wed Jul 08 15:42:30 2015 +0000
@@ -5,6 +5,7 @@
 #include "Distance.h"
 
 void printArray(int array[6]);
+void data(int sensor_number, int speed);
 
  //mbed pins
 extern Serial pc;                                                                   //defines the communication between MBed and pc
@@ -14,10 +15,10 @@
  
 //c++ variables
     time_t sensor_time ;                            //time at which sensor is broken
-    int timeDiff;                          //time between 2 sensors - not used right now
+    int timeDiff;                          //time between 2 sensors - not used right now   
+    float speed;
     int times[6];                                //array the size of #pins
-    float speed;
-                                                  
+    double speeds[6];                                //array of speeds            
 int calculate(float distance)
 {
     pc.printf("new program \n");                                            //alert user of initialisation   
@@ -40,11 +41,13 @@
              pc.printf(" timediff: %d s \t", timeDiff); 
              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(times);
+      //printArray(speeds);
   
 }
 
@@ -54,5 +57,9 @@
         {
              pc.printf(" %d : %d  \t", i,times[i]); 
          }
+         for (int i = 0; i < 5 ; i++)                                     //printing to Datalog                            
+        {
+             data( i,times[i]); 
+         }
          
       }