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