![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
02/07/15
Dependencies: mbed
Diff: Calculate.cpp
- Revision:
- 26:4289549b2d21
- Parent:
- 25:bab86a12e9ad
- Child:
- 29:3ef0b7773ff6
- Child:
- 30:ab3a436e8968
--- a/Calculate.cpp Tue Jul 07 14:12:51 2015 +0000 +++ b/Calculate.cpp Tue Jul 07 14:52:10 2015 +0000 @@ -3,36 +3,37 @@ #include <string> #include <iostream> //mbed pins -extern Serial pc; - //defines the communication between MBed and pc -DigitalIn sensor[3] = {p8,p9,p10}; //input from diode. Digital 1 is beam unbroken? - - -DigitalOut led(LED1); +extern Serial pc; //defines the communication between MBed and pc +int NoOfPins = 6; //for how many sensors there are +DigitalIn sensor[6] = {p8,p9,p10,p11,p12,p13}; //array of sensors. //c++ variables - time_t sensor_time ; - double sensor2Seconds; - double sensor3Seconds; - //testing purposes -int calculate() + time_t sensor_time ; //time at which sensor is broken + double timeDifference; //time between 2 sensors - not used right now + double times[6]; //array the size of #pins + +int calculate() //the one method { pc.printf("new program \n"); //alert user of initialisation - int i = 0; - while( i < 3) + int i = 0; //for counter + while( i < NoOfPins) //for every pin { - while(!sensor[i]) + while(!sensor[i]) //while not pin. while loop ends after last sensor { - if(sensor[i + 1]) { - sensor_time = time(NULL); - i++; - } //error checking incase next one is done + if(sensor[i + 1]) { //error bypassing measures incase one is missed will continue as normal + sensor_time = time(NULL); //get time + i++; //error bypassing incase next one is done + } } - sensor_time = time(NULL); - pc.printf(" %dth sensor %d : \t", i,sensor_time); - i++; - } + sensor_time = time(NULL); //get time + pc.printf(" %dth sensor %d : \t", i,sensor_time); //print time + times[i] = sensor_time; //add tiem to the array + i++; //move onto next sensor + } pc.printf("Calculate completed"); + for (int i = 6 - 1; i >= 0; i--) { //code for printing the array times + pc.printf("%d", times[i]); //^ + } }