02/07/15

Dependencies:   mbed

Dependents:   TabbedGUIMbed

Committer:
aidanPJG
Date:
Tue Jul 07 12:46:56 2015 +0000
Revision:
22:34bc2f2f5b09
Parent:
20:0b2279011691
Child:
24:92600b1d15b1
adams with uncommented calculate code;

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 22:34bc2f2f5b09 5
aidanPJG 22:34bc2f2f5b09 6 Serial pc(USBTX, USBRX); // tx, rx //defines the communication between MBed and pc
aidanPJG 22:34bc2f2f5b09 7 DigitalIn sensor1(p8); //input from diode. Digital 1 is beam unbroken?
aidanPJG 22:34bc2f2f5b09 8 DigitalIn sensor2(p9);
aidanPJG 22:34bc2f2f5b09 9 DigitalIn sensor3(p10);
aidanPJG 22:34bc2f2f5b09 10 DigitalIn sensor4(p11);
aidanPJG 22:34bc2f2f5b09 11 DigitalOut led(LED1);
aidanPJG 22:34bc2f2f5b09 12 //testing purposes
aidanPJG 22:34bc2f2f5b09 13 int calculate()
aidanPJG 22:34bc2f2f5b09 14 {
aidanPJG 22:34bc2f2f5b09 15
aidanPJG 22:34bc2f2f5b09 16 pc.printf("new program \n"); //alert user of initialisation
aidanPJG 22:34bc2f2f5b09 17
aidanPJG 22:34bc2f2f5b09 18 time_t sensor1_time ;
aidanPJG 22:34bc2f2f5b09 19 time_t sensor2_time ;
aidanPJG 22:34bc2f2f5b09 20 time_t sensor3_time ;
aidanPJG 22:34bc2f2f5b09 21 double sensor2Seconds;
aidanPJG 22:34bc2f2f5b09 22 double sensor3Seconds;
aidanPJG 22:34bc2f2f5b09 23
aidanPJG 22:34bc2f2f5b09 24 // while(!sensor4) //until last sensor because that will be when its over.
aidanPJG 22:34bc2f2f5b09 25 // {
aidanPJG 22:34bc2f2f5b09 26 if (sensor1) //checks the digital input from the diode.
aidanPJG 22:34bc2f2f5b09 27 {
aidanPJG 22:34bc2f2f5b09 28
aidanPJG 22:34bc2f2f5b09 29 led = 1;
aidanPJG 22:34bc2f2f5b09 30 sensor1_time = time(NULL);
aidanPJG 22:34bc2f2f5b09 31 }
aidanPJG 22:34bc2f2f5b09 32 if (sensor2) //checks the digital input from the diode.
aidanPJG 22:34bc2f2f5b09 33 {
aidanPJG 22:34bc2f2f5b09 34
aidanPJG 22:34bc2f2f5b09 35 led = 1;
aidanPJG 22:34bc2f2f5b09 36 sensor2_time = time(NULL);
aidanPJG 22:34bc2f2f5b09 37 sensor2Seconds = difftime(sensor2_time, sensor1_time);
aidanPJG 22:34bc2f2f5b09 38 pc.printf(" 2nd time %d : \t", sensor2Seconds);
aidanPJG 22:34bc2f2f5b09 39 }
aidanPJG 22:34bc2f2f5b09 40 if (sensor3) //checks the digital input from the diode.
aidanPJG 22:34bc2f2f5b09 41 {
aidanPJG 22:34bc2f2f5b09 42
aidanPJG 22:34bc2f2f5b09 43 led = 1;
aidanPJG 22:34bc2f2f5b09 44 sensor3_time = time(NULL);
aidanPJG 22:34bc2f2f5b09 45 sensor3Seconds = difftime(sensor3_time, sensor2_time);
aidanPJG 22:34bc2f2f5b09 46 pc.printf("3rd time %d : \t", sensor3Seconds );
aidanPJG 22:34bc2f2f5b09 47 }
aidanPJG 22:34bc2f2f5b09 48
aidanPJG 22:34bc2f2f5b09 49 // }
aidanPJG 22:34bc2f2f5b09 50 }