something

Dependencies:   mbed Motor LSM9DS1_Library_cal PinDetect HC_SR04_Ultrasonic_Library

Revision:
8:2d0fc244cc65
Parent:
7:5667ce16d526
Child:
9:ec0ceec8f5f5
--- a/main.cpp	Sun Nov 25 20:09:50 2018 +0000
+++ b/main.cpp	Wed Nov 28 18:28:04 2018 +0000
@@ -8,7 +8,8 @@
 // Global Variables:
 bool tr = true;
 bool turnflag = false;
-
+int leftdistance= 0;
+int rightdistance = 0;
 //---------------------|
 // PIN INITIALIZATIONS |
 //---------------------|
@@ -114,13 +115,38 @@
     }
 }
 
+void dist2(int distance)   // left sensor interrupt
+{
+    /*if (distance < 150) {
+     pc.printf("Left Sensor trigg"); 
+    }
+    else {
+        pc.printf("Left Sensor echo");
+    }*/
+    leftdistance = distance; 
+}
+
+void dist3(int distance)  // right sensor interrupt
+{
+    /*if (distance < 150) {
+     pc.printf("Right Sensor trigg"); 
+    }
+    else {
+        pc.printf("Right Sensor echo");
+    }*/
+    rightdistance = distance;
+}
+
+
 //------------------------------|
 // PIN INITIALIZATIONS (cont'd) |
 //------------------------------|
 // Setup Ultrasonic Sensor pins:
 ultrasonic usensor(p13, p14, .07, 1, &dist);  // trigger to p13, echo to p14...
-                                              // update every .07 secs w/ timeout after 1 sec...
+                                             // update every .07 secs w/ timeout after 1 sec...
                                               // call "dist" when the distance changes...
+ultrasonic usensor2(p13, p26, .07, 1, &dist2);  // left trigger
+ultrasonic usensor3(p13, p25, .07, 1, &dist3); //right trigger
 
 //---------------|
 // MAIN FUNCTION |
@@ -130,14 +156,18 @@
     sw.mode(PullUp);
     // Initialize the Ultrasonic Sensor:
     usensor.startUpdates();
-    
+    usensor2.startUpdates();
+    usensor3.startUpdates(); 
     // Initialize the Timer:
     t.start();
     while(!sw) {
     
         usensor.checkDistance();
-        
-        wait(0.1);
+        usensor2.checkDistance();
+        usensor3.checkDistance();
+        pc.printf("Left Distance %d mm\r\n", leftdistance);
+        pc.printf("Right Distance %d mm\r\n", rightdistance);
+        wait(1);
     }
 }