working code

Dependencies:   mbed

Fork of Working_Client_Code by iX

Revision:
7:1119c6781d17
Parent:
6:1c35ca876e09
Child:
8:f277f86f75bb
diff -r 1c35ca876e09 -r 1119c6781d17 main.cpp
--- a/main.cpp	Fri Jun 10 09:42:38 2016 +0000
+++ b/main.cpp	Fri Jun 10 09:51:57 2016 +0000
@@ -109,6 +109,28 @@
     }
     return p;
 }
+
+
+//A FUNCTION TO FIND THE RANGE-----------------------------------------------------------
+
+int obstruction_finder()
+{
+    AnalogIn ranger(p15);
+    float r;
+    float d;
+    int obstruction;
+    r = ranger;
+    d = r / 0.00084;
+    if (d < 20) {
+        obstruction = 1;
+    } else {
+        obstruction = 0;
+    }
+    return obstruction;
+}
+
+//A FUNCTION TO FIND THE RANGE--------------------------------------------------------------
+
 int main()
 {
     int range=3456;
@@ -218,12 +240,13 @@
                        INFO("Ready");
                        wait(2);
                        char buf[32];
+                       range = obstruction_finder();
                        sprintf(buf,"Range=%04d\r\n",range);
                         //dev.printf("AT+CIPSERVER= 1,6060"); 
                        dev.printf("AT+CIPSEND=0,%d\r\n",strlen(buf));  //10 = length of string being sent
                        wait(2);
                         dev.printf("%s",buf);  //10 = length of string being sent
-                       range=(range++)%6000;
+                     //range=(range++)%6000;
             
                        state=9;
                     }