![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
02/07/15
Dependencies: mbed
Calculate.cpp@29:3ef0b7773ff6, 2015-07-07 (annotated)
- Committer:
- aidanPJG
- Date:
- Tue Jul 07 16:00:43 2015 +0000
- Revision:
- 29:3ef0b7773ff6
- Parent:
- 26:4289549b2d21
Simple program to test a pin is receiving a value. Can be used to test sensors are sending.
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 | 29:3ef0b7773ff6 | 7 | //int NoOfPins = 6; //for how many sensors there are |
aidanPJG | 29:3ef0b7773ff6 | 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 | 26:4289549b2d21 | 14 | int calculate() //the one method |
aidanPJG | 22:34bc2f2f5b09 | 15 | { |
aidanPJG | 22:34bc2f2f5b09 | 16 | pc.printf("new program \n"); //alert user of initialisation |
aidanPJG | 22:34bc2f2f5b09 | 17 | |
aidanPJG | 26:4289549b2d21 | 18 | int i = 0; //for counter |
aidanPJG | 29:3ef0b7773ff6 | 19 | while( i < 6) //for every pin |
aidanPJG | 25:bab86a12e9ad | 20 | { |
aidanPJG | 26:4289549b2d21 | 21 | while(!sensor[i]) //while not pin. while loop ends after last sensor |
aidanPJG | 22:34bc2f2f5b09 | 22 | { |
aidanPJG | 29:3ef0b7773ff6 | 23 | if(sensor[i + 1]) { //error bypassing measures incase one is missed will continue as normal |
aidanPJG | 26:4289549b2d21 | 24 | sensor_time = time(NULL); //get time |
aidanPJG | 29:3ef0b7773ff6 | 25 | // i++; |
aidanPJG | 29:3ef0b7773ff6 | 26 | //error bypassing incase next one is done |
aidanPJG | 26:4289549b2d21 | 27 | } |
aidanPJG | 22:34bc2f2f5b09 | 28 | } |
aidanPJG | 26:4289549b2d21 | 29 | sensor_time = time(NULL); //get time |
aidanPJG | 26:4289549b2d21 | 30 | pc.printf(" %dth sensor %d : \t", i,sensor_time); //print time |
aidanPJG | 26:4289549b2d21 | 31 | times[i] = sensor_time; //add tiem to the array |
aidanPJG | 26:4289549b2d21 | 32 | i++; //move onto next sensor |
aidanPJG | 26:4289549b2d21 | 33 | } |
aidanPJG | 25:bab86a12e9ad | 34 | pc.printf("Calculate completed"); |
aidanPJG | 26:4289549b2d21 | 35 | for (int i = 6 - 1; i >= 0; i--) { //code for printing the array times |
aidanPJG | 26:4289549b2d21 | 36 | pc.printf("%d", times[i]); //^ |
aidanPJG | 26:4289549b2d21 | 37 | } |
aidanPJG | 22:34bc2f2f5b09 | 38 | |
aidanPJG | 25:bab86a12e9ad | 39 | |
aidanPJG | 22:34bc2f2f5b09 | 40 | } |