![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
02/07/15
Dependencies: mbed
Calculate.cpp@24:92600b1d15b1, 2015-07-07 (annotated)
- Committer:
- aidanPJG
- Date:
- Tue Jul 07 12:56:24 2015 +0000
- Revision:
- 24:92600b1d15b1
- Parent:
- 19:a3edf2c547e1
- Parent:
- 22:34bc2f2f5b09
- Child:
- 25:bab86a12e9ad
proper merge this time;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aidanPJG | 22:34bc2f2f5b09 | 1 | #include "mbed.h" |
aidanPJG | 22:34bc2f2f5b09 | 2 | #include <time.h> |
aidanPJG | 22:34bc2f2f5b09 | 3 | #include <string> |
aidanPJG | 22:34bc2f2f5b09 | 4 | #include <iostream> |
aidanPJG | 19:a3edf2c547e1 | 5 | //mbed pins |
aidanPJG | 22:34bc2f2f5b09 | 6 | Serial pc(USBTX, USBRX); // tx, rx //defines the communication between MBed and pc |
aidanPJG | 22:34bc2f2f5b09 | 7 | DigitalIn sensor1(p8); //input from diode. Digital 1 is beam unbroken? |
aidanPJG | 22:34bc2f2f5b09 | 8 | DigitalIn sensor2(p9); |
aidanPJG | 18:bb632df62f51 | 9 | DigitalIn sensor3(p10); |
aidanPJG | 22:34bc2f2f5b09 | 10 | DigitalOut led(LED1); |
aidanPJG | 19:a3edf2c547e1 | 11 | //c++ variables |
aidanPJG | 19:a3edf2c547e1 | 12 | time_t sensor1_time ; |
aidanPJG | 19:a3edf2c547e1 | 13 | time_t sensor2_time ; |
aidanPJG | 19:a3edf2c547e1 | 14 | time_t sensor3_time ; |
aidanPJG | 19:a3edf2c547e1 | 15 | double sensor2Seconds; |
aidanPJG | 19:a3edf2c547e1 | 16 | double sensor3Seconds; |
aidanPJG | 22:34bc2f2f5b09 | 17 | //testing purposes |
aidanPJG | 22:34bc2f2f5b09 | 18 | int calculate() |
aidanPJG | 22:34bc2f2f5b09 | 19 | { |
aidanPJG | 22:34bc2f2f5b09 | 20 | |
aidanPJG | 22:34bc2f2f5b09 | 21 | pc.printf("new program \n"); //alert user of initialisation |
aidanPJG | 22:34bc2f2f5b09 | 22 | |
aidanPJG | 19:a3edf2c547e1 | 23 | |
aidanPJG | 18:bb632df62f51 | 24 | |
aidanPJG | 18:bb632df62f51 | 25 | //while(1){ |
aidanPJG | 18:bb632df62f51 | 26 | |
aidanPJG | 18:bb632df62f51 | 27 | while (!sensor1) //continuously checks sensor |
aidanPJG | 18:bb632df62f51 | 28 | { |
aidanPJG | 18:bb632df62f51 | 29 | if (sensor1) //if sensor broken do this code also while leave while loop. |
aidanPJG | 18:bb632df62f51 | 30 | { |
aidanPJG | 18:bb632df62f51 | 31 | led = 1; |
aidanPJG | 18:bb632df62f51 | 32 | sensor1_time = time(NULL); |
aidanPJG | 18:bb632df62f51 | 33 | pc.printf(" 1nd sensor %d : \t", sensor1_time); |
aidanPJG | 19:a3edf2c547e1 | 34 | //break; |
aidanPJG | 18:bb632df62f51 | 35 | } |
aidanPJG | 18:bb632df62f51 | 36 | // break; |
aidanPJG | 22:34bc2f2f5b09 | 37 | } |
aidanPJG | 18:bb632df62f51 | 38 | while (!sensor2) //checks the digital input from the diode. |
aidanPJG | 22:34bc2f2f5b09 | 39 | { |
aidanPJG | 18:bb632df62f51 | 40 | if (sensor2) |
aidanPJG | 18:bb632df62f51 | 41 | { |
aidanPJG | 18:bb632df62f51 | 42 | led = 1; |
aidanPJG | 18:bb632df62f51 | 43 | sensor2_time = time(NULL); |
aidanPJG | 18:bb632df62f51 | 44 | pc.printf(" 2nd sensor %d : \t", sensor2_time); |
aidanPJG | 19:a3edf2c547e1 | 45 | // break; |
aidanPJG | 18:bb632df62f51 | 46 | } |
aidanPJG | 18:bb632df62f51 | 47 | //break; |
aidanPJG | 22:34bc2f2f5b09 | 48 | } |
aidanPJG | 18:bb632df62f51 | 49 | while (!sensor3) //checks the digital input from the diode. |
aidanPJG | 22:34bc2f2f5b09 | 50 | { |
aidanPJG | 18:bb632df62f51 | 51 | if (sensor3) |
aidanPJG | 18:bb632df62f51 | 52 | { |
aidanPJG | 18:bb632df62f51 | 53 | led = 1; |
aidanPJG | 18:bb632df62f51 | 54 | sensor3_time = time(NULL); |
aidanPJG | 18:bb632df62f51 | 55 | pc.printf("3rd sensor %d : \t", sensor3_time); |
aidanPJG | 19:a3edf2c547e1 | 56 | // break; |
aidanPJG | 18:bb632df62f51 | 57 | } |
aidanPJG | 22:34bc2f2f5b09 | 58 | } |
aidanPJG | 19:a3edf2c547e1 | 59 | pc.printf("end results: \t", sensor1_time, sensor2_time, sensor3_time); |
aidanPJG | 18:bb632df62f51 | 60 | pc.printf("Calculate completed"); |
aidanPJG | 22:34bc2f2f5b09 | 61 | |
aidanPJG | 18:bb632df62f51 | 62 | //} |
aidanPJG | 22:34bc2f2f5b09 | 63 | } |