![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
02/07/15
Dependencies: mbed
Calculate.cpp@30:ab3a436e8968, 2015-07-08 (annotated)
- Committer:
- aidanPJG
- Date:
- Wed Jul 08 07:47:28 2015 +0000
- Revision:
- 30:ab3a436e8968
- Parent:
- 26:4289549b2d21
- Child:
- 31:bea1117f14fb
calculate now completing when run; ;
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 | 26:4289549b2d21 | 6 | extern Serial pc; //defines the communication between MBed and pc |
aidanPJG | 26:4289549b2d21 | 7 | int NoOfPins = 6; //for how many sensors there are |
aidanPJG | 30:ab3a436e8968 | 8 | DigitalIn sensor[6] = {p5,p6,p7,p8,p9,p10} ; //array of sensors. |
aidanPJG | 19:a3edf2c547e1 | 9 | //c++ variables |
aidanPJG | 26:4289549b2d21 | 10 | time_t sensor_time ; //time at which sensor is broken |
aidanPJG | 26:4289549b2d21 | 11 | double timeDifference; //time between 2 sensors - not used right now |
aidanPJG | 26:4289549b2d21 | 12 | double times[6]; //array the size of #pins |
aidanPJG | 26:4289549b2d21 | 13 | |
aidanPJG | 30:ab3a436e8968 | 14 | int calculate() |
aidanPJG | 22:34bc2f2f5b09 | 15 | { |
aidanPJG | 22:34bc2f2f5b09 | 16 | pc.printf("new program \n"); //alert user of initialisation |
aidanPJG | 22:34bc2f2f5b09 | 17 | |
aidanPJG | 30:ab3a436e8968 | 18 | int i = 0; |
aidanPJG | 30:ab3a436e8968 | 19 | while( i < 6) |
aidanPJG | 25:bab86a12e9ad | 20 | { |
aidanPJG | 30:ab3a436e8968 | 21 | while(!sensor[i]) |
aidanPJG | 22:34bc2f2f5b09 | 22 | { |
aidanPJG | 30:ab3a436e8968 | 23 | if(sensor[i + 1]) { |
aidanPJG | 30:ab3a436e8968 | 24 | sensor_time = time(NULL); |
aidanPJG | 30:ab3a436e8968 | 25 | i++; |
aidanPJG | 30:ab3a436e8968 | 26 | } //error checking incase next one is done |
aidanPJG | 22:34bc2f2f5b09 | 27 | } |
aidanPJG | 30:ab3a436e8968 | 28 | sensor_time = time(NULL); |
aidanPJG | 30:ab3a436e8968 | 29 | pc.printf(" %dth sensor %d : \t", i,sensor_time); |
aidanPJG | 30:ab3a436e8968 | 30 | i++; |
aidanPJG | 30:ab3a436e8968 | 31 | } |
aidanPJG | 25:bab86a12e9ad | 32 | pc.printf("Calculate completed"); |
aidanPJG | 22:34bc2f2f5b09 | 33 | |
aidanPJG | 25:bab86a12e9ad | 34 | |
aidanPJG | 22:34bc2f2f5b09 | 35 | } |
aidanPJG | 30:ab3a436e8968 | 36 | |
aidanPJG | 30:ab3a436e8968 | 37 |