![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
02/07/15
Dependencies: mbed
Diff: Calculate.cpp
- Revision:
- 18:bb632df62f51
- Parent:
- 14:dee4cef00b32
- Child:
- 19:a3edf2c547e1
diff -r d9fb4a3780c7 -r bb632df62f51 Calculate.cpp --- a/Calculate.cpp Tue Jul 07 08:47:35 2015 +0000 +++ b/Calculate.cpp Tue Jul 07 11:00:08 2015 +0000 @@ -6,8 +6,7 @@ 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); -DigitalIn sensor4(p11); +DigitalIn sensor3(p10); DigitalOut led(LED1); //testing purposes int calculate() @@ -20,31 +19,39 @@ time_t sensor3_time ; double sensor2Seconds; double sensor3Seconds; - - // while(!sensor4) //until last sensor because that will be when its over. - // { - if (sensor1) //checks the digital input from the diode. - { - - led = 1; - sensor1_time = time(NULL); + +//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; } - if (sensor2) //checks the digital input from the diode. + while (!sensor2) //checks the digital input from the diode. { - - led = 1; - sensor2_time = time(NULL); - sensor2Seconds = difftime(sensor2_time, sensor1_time); - pc.printf(" 2nd time %d : \t", sensor2Seconds); + if (sensor2) + { + led = 1; + sensor2_time = time(NULL); + pc.printf(" 2nd sensor %d : \t", sensor2_time); + } + //break; } - if (sensor3) //checks the digital input from the diode. + while (!sensor3) //checks the digital input from the diode. { - - led = 1; - sensor3_time = time(NULL); - sensor3Seconds = difftime(sensor3_time, sensor2_time); - pc.printf("3rd time %d : \t", sensor3Seconds ); + if (sensor3) + { + led = 1; + sensor3_time = time(NULL); + pc.printf("3rd sensor %d : \t", sensor3_time); + } } + pc.printf("Calculate completed"); - // } +//} }