02/07/15

Dependencies:   mbed

Dependents:   TabbedGUIMbed

Revision:
62:9de96bcfdb4b
Parent:
61:e7f2a0e38360
Child:
63:7d2bff227f65
diff -r e7f2a0e38360 -r 9de96bcfdb4b Calculate.cpp
--- a/Calculate.cpp	Tue Aug 04 10:24:39 2015 +0000
+++ b/Calculate.cpp	Tue Aug 04 14:37:54 2015 +0000
@@ -14,13 +14,13 @@
 
 //********c++ variables*******************************   
     Timer t;
-    double timeDiff;                          //time between 2 sensors - not used right now   
-    double speed;
+    double timeDiff= 0;                          //time between 2 sensors - not used right now   
+    double speed = 0;
     double times[20];                                //array the size of #pins
     double speeds[20];                                //array of speeds 
-    double avgtime;    
-    double avgspeed;
-    double avgdistance;
+    double avgtime= 0;;    
+    double avgspeed = 0;
+    double avgdistance = 0;
 
       
 int calculate(double distance, int NoOfPins)
@@ -38,13 +38,12 @@
                     
                 }                                                        
             }
-        t.start();                                                                //starts the timer once, doesn't do anything next iteration
-        timeDiff =  t.read();                                                       //reads what the timer is currently at
-        t.reset();                                                                 //starts the timer again from 0.
-        times[i] = timeDiff;                                                 //adds sensor times to array for logging.
-        
+            t.start();                                                                //starts the timer once, doesn't do anything next iteration
+            timeDiff =  t.read();                                                       //reads what the timer is currently at
+            t.reset();                                                                 //starts the timer again from 0.
+            times[i] = timeDiff;                                                 //adds sensor times to array for logging.
+            
        pc.printf(" timediff: %lf\n", timeDiff); //testing
-
                
                                                               //to ensure it is not the first one
                  speed = 60* (distance / timeDiff);                //multiplied by 60 to get meters per minute