![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
02/07/15
Dependencies: mbed
Diff: Calculate.cpp
- Revision:
- 57:f94834892570
- Parent:
- 56:bf08d9e50ccc
- Child:
- 58:c729d48cbeef
diff -r bf08d9e50ccc -r f94834892570 Calculate.cpp --- a/Calculate.cpp Tue Jul 28 14:40:26 2015 +0000 +++ b/Calculate.cpp Tue Jul 28 15:12:02 2015 +0000 @@ -4,8 +4,8 @@ #include <iostream> #include "Distance.h" -void printArray(double array[20], int timesArray[20], int NoOfPins); -void data(int sensor_number, int time, double speed); +void printArray(double array[20], double timesArray[20], int NoOfPins); +void data(int sensor_number, double time, double speed); //mbed pins extern Serial pc; //defines the communication between MBed and pc @@ -17,8 +17,8 @@ time_t sensor_time ; //time at which sensor is broken Timer t; double timeDiff; //time between 2 sensors - not used right now - float speed; - int times[20]; //array the size of #pins + double speed; + double times[20]; //array the size of #pins double speeds[20]; //array of speeds @@ -35,23 +35,18 @@ { if(sensor[i + 1]) { - printf("it skipped a sensor"); - sensor_time = time(NULL); + printf("it skipped sensor % d", i); i++; } //error checking incase next one is done } - // 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); + t.start(); //starts the timer + 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 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; @@ -59,15 +54,15 @@ i++; } pc.printf(" \n Calculate completed \n"); //alert to let user know it completed - // printArray(speeds, times, NoOfPins); + printArray(speeds, times, NoOfPins); } -void printArray(double array[20], int timesArray[20], int NoOfPins) +void printArray(double array[20], double timesArray[20], int NoOfPins) { for (int i = 0; i < NoOfPins ; i++) //printing module for array { - pc.printf(" Sensor : %d Time %d Speed %f \n", i,times[i],speeds[i]); + pc.printf(" Sensor : %d Time %lf Speed %f \n", i,times[i],speeds[i]); // pc.printf(" %d : %d \t", i,times[i]); } for (int i = 0; i < NoOfPins ; i++) //printing to Datalog