![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
02/07/15
Dependencies: mbed
Diff: Calculate.cpp
- Revision:
- 25:bab86a12e9ad
- Parent:
- 24:92600b1d15b1
- Child:
- 26:4289549b2d21
--- a/Calculate.cpp Tue Jul 07 12:56:24 2015 +0000 +++ b/Calculate.cpp Tue Jul 07 14:12:51 2015 +0000 @@ -3,61 +3,36 @@ #include <string> #include <iostream> //mbed pins -Serial pc(USBTX, USBRX); // tx, rx //defines the communication between MBed and pc -DigitalIn sensor1(p8); //input from diode. Digital 1 is beam unbroken? -DigitalIn sensor2(p9); -DigitalIn sensor3(p10); +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); //c++ variables - time_t sensor1_time ; - time_t sensor2_time ; - time_t sensor3_time ; + time_t sensor_time ; double sensor2Seconds; double sensor3Seconds; //testing purposes int calculate() { - pc.printf("new program \n"); //alert user of initialisation - - -//while(1){ - - while (!sensor1) //continuously checks sensor - { - if (sensor1) //if sensor broken do this code also while leave while loop. - { - led = 1; - sensor1_time = time(NULL); - pc.printf(" 1nd sensor %d : \t", sensor1_time); - //break; - } - // break; - } - while (!sensor2) //checks the digital input from the diode. + int i = 0; + while( i < 3) + { + while(!sensor[i]) { - if (sensor2) - { - led = 1; - sensor2_time = time(NULL); - pc.printf(" 2nd sensor %d : \t", sensor2_time); - // break; - } - //break; + if(sensor[i + 1]) { + sensor_time = time(NULL); + i++; + } //error checking incase next one is done } - while (!sensor3) //checks the digital input from the diode. - { - if (sensor3) - { - led = 1; - sensor3_time = time(NULL); - pc.printf("3rd sensor %d : \t", sensor3_time); - // break; - } - } - pc.printf("end results: \t", sensor1_time, sensor2_time, sensor3_time); - pc.printf("Calculate completed"); + sensor_time = time(NULL); + pc.printf(" %dth sensor %d : \t", i,sensor_time); + i++; + } + pc.printf("Calculate completed"); -//} + }