![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
02/07/15
Dependencies: mbed
Diff: Calculate.cpp
- Revision:
- 33:929f1755664b
- Parent:
- 32:792c4239a738
- Child:
- 38:da262dc4f90a
--- a/Calculate.cpp Wed Jul 08 08:13:10 2015 +0000 +++ b/Calculate.cpp Wed Jul 08 08:37:07 2015 +0000 @@ -2,6 +2,7 @@ #include <time.h> #include <string> #include <iostream> +//#include "Distance.h" //mbed pins extern Serial pc; //defines the communication between MBed and pc @@ -13,8 +14,9 @@ time_t sensor_time ; //time at which sensor is broken int timeDiff; //time between 2 sensors - not used right now int times[6]; //array the size of #pins + float speed; -int calculate() +int calculate(float distance) { pc.printf("new program \n"); //alert user of initialisation @@ -28,14 +30,15 @@ i++; } //error checking incase next one is done } - sensor_time = time(NULL); + sensor_time = time(NULL); //gets current time pc.printf(" %dth sensor: %d \t", i,sensor_time); + pc.printf(" distance is: %f \t", distance); times[i] = sensor_time; //adds sensor times to array for logging. - if ( i > 0) { //to ensure it is not the first one - // pc.printf(" time[i] : %d \t", times[i]); //testing - // pc.printf(" time[i -1] : %d \t", times[i -1 ]); //testing - timeDiff = difftime(times[i], times[i-1]); - pc.printf(" timediff: %d \t", timeDiff); + 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 \t", timeDiff); + speed = distance / timeDiff; + pc.printf(" speed : %f \t", speed); } i++; }