Ultrasonic distance meter mede with micro:bit and Grove Inventor Kit

Dependencies:   DigitDisplay RangeFinder microbit

Fork of microbit-component-display by BBC

Revision:
1:ed667cae3667
Parent:
0:0c37474c8541
--- a/main.cpp	Wed Apr 20 14:01:36 2016 +0000
+++ b/main.cpp	Thu Aug 24 09:05:15 2017 +0000
@@ -1,13 +1,23 @@
-/* See 
- * http://lancaster-university.github.io/microbit-docs/advanced/ 
- * for docs about using the micro:bit library
-*/
 #include "MicroBit.h"
+#include "DigitDisplay.h"
+#include "RangeFinder.h"
 
 MicroBitDisplay display;
+//DigitDisplay digit(P0_3, P0_22); // P0/P14
+DigitDisplay digit(P0_2, P0_21); // P1/P15
+
+RangeFinder rf(P0_3, 10, 5800.0, 100000);
 
 int main()
 {
-    while(1)
-        display.scroll(":)");
+    float d;
+
+    while(1) {
+        d = rf.read_m() * 100;
+        digit.write(0,(int)d / 1000 % 10);
+        digit.write(1,(int)d / 100 % 10);
+        digit.write(2,(int)d / 10 % 10);
+        digit.write(3,(int)d / 1 % 10);
+        wait(1);
+    }
 }
\ No newline at end of file