02/07/15

Dependencies:   mbed

Dependents:   TabbedGUIMbed

Committer:
aidanPJG
Date:
Tue Jul 07 14:52:10 2015 +0000
Revision:
26:4289549b2d21
Parent:
25:bab86a12e9ad
Child:
29:3ef0b7773ff6
Child:
30:ab3a436e8968
commented code. Trying to add sensor times into array;

Who changed what in which revision?

UserRevisionLine numberNew 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 26:4289549b2d21 8 DigitalIn sensor[6] = {p8,p9,p10,p11,p12,p13}; //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 26:4289549b2d21 19 while( i < NoOfPins) //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 26:4289549b2d21 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 26:4289549b2d21 25 i++; //error bypassing incase next one is done
aidanPJG 26:4289549b2d21 26 }
aidanPJG 22:34bc2f2f5b09 27 }
aidanPJG 26:4289549b2d21 28 sensor_time = time(NULL); //get time
aidanPJG 26:4289549b2d21 29 pc.printf(" %dth sensor %d : \t", i,sensor_time); //print time
aidanPJG 26:4289549b2d21 30 times[i] = sensor_time; //add tiem to the array
aidanPJG 26:4289549b2d21 31 i++; //move onto next sensor
aidanPJG 26:4289549b2d21 32 }
aidanPJG 25:bab86a12e9ad 33 pc.printf("Calculate completed");
aidanPJG 26:4289549b2d21 34 for (int i = 6 - 1; i >= 0; i--) { //code for printing the array times
aidanPJG 26:4289549b2d21 35 pc.printf("%d", times[i]); //^
aidanPJG 26:4289549b2d21 36 }
aidanPJG 22:34bc2f2f5b09 37
aidanPJG 25:bab86a12e9ad 38
aidanPJG 22:34bc2f2f5b09 39 }