02/07/15

Dependencies:   mbed

Dependents:   TabbedGUIMbed

Committer:
aidanPJG
Date:
Tue Jul 07 14:12:51 2015 +0000
Revision:
25:bab86a12e9ad
Parent:
24:92600b1d15b1
Child:
26:4289549b2d21
Calculate able to tell when the beam is broken and print it

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 25:bab86a12e9ad 6 extern Serial pc;
aidanPJG 25:bab86a12e9ad 7 //defines the communication between MBed and pc
aidanPJG 25:bab86a12e9ad 8 DigitalIn sensor[3] = {p8,p9,p10}; //input from diode. Digital 1 is beam unbroken?
aidanPJG 25:bab86a12e9ad 9
aidanPJG 25:bab86a12e9ad 10
aidanPJG 22:34bc2f2f5b09 11 DigitalOut led(LED1);
aidanPJG 19:a3edf2c547e1 12 //c++ variables
aidanPJG 25:bab86a12e9ad 13 time_t sensor_time ;
aidanPJG 19:a3edf2c547e1 14 double sensor2Seconds;
aidanPJG 19:a3edf2c547e1 15 double sensor3Seconds;
aidanPJG 22:34bc2f2f5b09 16 //testing purposes
aidanPJG 22:34bc2f2f5b09 17 int calculate()
aidanPJG 22:34bc2f2f5b09 18 {
aidanPJG 22:34bc2f2f5b09 19 pc.printf("new program \n"); //alert user of initialisation
aidanPJG 22:34bc2f2f5b09 20
aidanPJG 25:bab86a12e9ad 21 int i = 0;
aidanPJG 25:bab86a12e9ad 22 while( i < 3)
aidanPJG 25:bab86a12e9ad 23 {
aidanPJG 25:bab86a12e9ad 24 while(!sensor[i])
aidanPJG 22:34bc2f2f5b09 25 {
aidanPJG 25:bab86a12e9ad 26 if(sensor[i + 1]) {
aidanPJG 25:bab86a12e9ad 27 sensor_time = time(NULL);
aidanPJG 25:bab86a12e9ad 28 i++;
aidanPJG 25:bab86a12e9ad 29 } //error checking incase next one is done
aidanPJG 22:34bc2f2f5b09 30 }
aidanPJG 25:bab86a12e9ad 31 sensor_time = time(NULL);
aidanPJG 25:bab86a12e9ad 32 pc.printf(" %dth sensor %d : \t", i,sensor_time);
aidanPJG 25:bab86a12e9ad 33 i++;
aidanPJG 25:bab86a12e9ad 34 }
aidanPJG 25:bab86a12e9ad 35 pc.printf("Calculate completed");
aidanPJG 22:34bc2f2f5b09 36
aidanPJG 25:bab86a12e9ad 37
aidanPJG 22:34bc2f2f5b09 38 }