02/07/15

Dependencies:   mbed

Dependents:   TabbedGUIMbed

main.cpp

Committer:
aidanPJG
Date:
2015-09-03
Revision:
71:60f06e7e50a3
Parent:
70:168d67695a65

File content as of revision 71:60f06e7e50a3:

#include "mbed.h"
#include "Calculate.h"
#include "Data.h"
#include "UserInput.h"
#include "AddDetails.h"

Serial pc(USBTX, USBRX);                // tx, rx  comms for the pc to talk to the mbed
DigitalOut led1(LED1);                  //led on the mbed, used for debugging   
DigitalOut led2(LED2);                   //"

string handshake();
void run();
int listen();

int main(void)                          //the first method that is run 
{
   
    if (handshake() == "success")              //if the handshake returns success message
    {
        run();                                 //then we run the program
    }      
    led2= 1;
}

string handshake()                                      //to test that the pc and mbed have comms
{   
            unsigned char input;                                //what the pc sends
             pc.printf("a\n");                                     //send the pc an 'a'
          
                 while(true)                                    //keep doing this
                 {
                     input = pc.getc();                         //what the pc sends
                     if (input == 'a')                          //did the pc send an 'a' as well?
                     {
                         led1 = 1;                                  //turn led on
                        return "success" ;                       //return "success"
                     }
                 }
}
void run()                                     
{
    int pins =  inputNoOfPins();                //gets number of pins
    double distance = inputDistance();         //gets the distance between the pins
    string date = inputDate();
    calculate(distance,pins,date);                       //runs calculate method.
}