02/07/15

Dependencies:   mbed

Dependents:   TabbedGUIMbed

Calculate.cpp

Committer:
aidanPJG
Date:
2015-07-07
Revision:
24:92600b1d15b1
Parent:
19:a3edf2c547e1
Parent:
22:34bc2f2f5b09
Child:
25:bab86a12e9ad

File content as of revision 24:92600b1d15b1:

#include "mbed.h"
#include <time.h>
#include <string>
#include <iostream>
 //mbed pins
Serial pc(USBTX, USBRX); // tx, rx                                          //defines the communication between MBed and pc
DigitalIn sensor1(p8);                                                        //input from diode. Digital 1 is beam unbroken?
DigitalIn sensor2(p9);  
DigitalIn sensor3(p10);   
DigitalOut led(LED1);    
//c++ variables
    time_t sensor1_time ;
    time_t sensor2_time ; 
    time_t sensor3_time ;
    double sensor2Seconds; 
    double sensor3Seconds;
                                                   //testing purposes 
int calculate()
{

    pc.printf("new program \n");                                            //alert user of initialisation   
      

    
//while(1){
                                   
        while (!sensor1)                                                          //continuously checks sensor
        {   
            if (sensor1)                                                            //if sensor broken do this code also while leave while loop.
            {     
                 led = 1;
                 sensor1_time = time(NULL); 
                 pc.printf(" 1nd sensor  %d : \t", sensor1_time);
                 //break;
            }
           // break;
        }
        while (!sensor2)                                                          //checks the digital input from the diode.
        {
            if (sensor2) 
            { 
                 led = 1;
                 sensor2_time = time(NULL);
                 pc.printf(" 2nd sensor  %d : \t", sensor2_time);
                // break;
            }
            //break;
        }
        while (!sensor3)                                                          //checks the digital input from the diode.
        {
           if (sensor3) 
            { 
                led = 1;
                 sensor3_time  = time(NULL);
                 pc.printf("3rd sensor  %d : \t", sensor3_time); 
                // break;
            }           
        }
        pc.printf("end results: \t", sensor1_time, sensor2_time, sensor3_time); 
        pc.printf("Calculate completed"); 
       
//}
}