Sevro_drive

Dependencies:   UoY-serial

Revision:
1:a7c3f3f3f2e7
Parent:
0:77209603a6fe
Child:
2:061e2fe8ae1a
--- a/main.cpp	Mon Jan 11 11:28:11 2021 +0000
+++ b/main.cpp	Thu Mar 18 10:41:40 2021 +0000
@@ -1,15 +1,23 @@
 #include "mbed.h"
 
+// Initialise D2 as an OPEN DRAIN output
+// It can be used in the same way as a normal DigitalOut
+DigitalInOut trig(D2, PIN_OUTPUT, OpenDrain, 0);
+
+// Initialise D3 as an input
+DigitalIn echo(D3);
+
 int main()
 {
-    int x = 4;
-    x = 6;
-    int y;
-    y = 2*x;
-    x = 7;
-    
-    printf("x:%d y:%d\n", x, y);
-    
-    // Do nothing, forever...
-    while (true);
+    while(true) {
+        // Send 10us trigger pulse
+        trig = true;
+        wait_us(10);
+        trig = false;
+        
+        while(!echo); // Wait for echo pulse to start
+        while(echo);  // Wait for echo pulse to end
+        printf("Echo received\n");
+        thread_sleep_for(500);
+    }
 }