02/07/15

Dependencies:   mbed

Dependents:   TabbedGUIMbed

Revision:
70:168d67695a65
Parent:
69:74bffa1d3f7f
Child:
71:60f06e7e50a3
--- a/main.cpp	Thu Aug 27 14:32:20 2015 +0000
+++ b/main.cpp	Thu Sep 03 15:10:51 2015 +0000
@@ -4,41 +4,42 @@
 #include "UserInput.h"
 #include "AddDetails.h"
 
-Serial pc(USBTX, USBRX); // tx, rx 
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
+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)
+int main(void)                          //the first method that is run 
 {
    
-    if (handshake() == "success")
+    if (handshake() == "success")              //if the handshake returns success message
     {
-        run();
+        run();                                 //then we run the program
     }      
     led2= 1;
 }
 
-string handshake()
-{
-            unsigned char input;
-             pc.printf("a\n");
+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)
+                 while(true)                                    //keep doing this
                  {
-                     input = pc.getc();
-                     if (input == 'a')
+                     input = pc.getc();                         //what the pc sends
+                     if (input == 'a')                          //did the pc send an 'a' as well?
                      {
-                         led1 = 1; 
-                        return "success" ;// run();
+                         led1 = 1;                                  //turn led on
+                        return "success" ;                       //return "success"
                      }
                  }
 }
-void run()
+void run()                                     
 {
     int pins =  inputNoOfPins();                //gets number of pins
     double distance = inputDistance();         //gets the distance between the pins
-    calculate(distance,pins);    
+    calculate(distance,pins);                       //runs calculate method.
 }        
\ No newline at end of file