XL-MaxSonar MB1260 高度計のテストプログラムです。

Dependencies:   mbed

Revision:
0:ee1032401c3e
Child:
1:29f4aa7418eb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 30 11:43:17 2016 +0000
@@ -0,0 +1,25 @@
+#include "mbed.h"
+
+Serial pc(USBTX,USBRX);
+Timer sonerTimer;
+InterruptIn sonerPin(p22);
+double sonerDistTime=0;
+
+void sonerInterruptStart(){
+    sonerTimer.start();
+}
+void sonerInterruptStop(){
+    sonerTimer.stop();
+    sonerDistTime = sonerTimer.read_us();
+    sonerTimer.reset();
+}
+
+int main() {
+    sonerPin.rise(&sonerInterruptStart);
+    sonerPin.fall(&sonerInterruptStop);
+    while(1) {
+        pc.printf("DistTime: %f\n\r",sonerDistTime);
+        pc.printf("CalculatedDist: %f\n\r",sonerDistTime/58.0);
+        wait(0.5);
+    }
+}