MBED_Afstandsmeter Niek

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
niek_beumer
Date:
Wed Apr 25 18:33:42 2018 +0000
Commit message:
afstandsmeter

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 4a7c5016ab03 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Apr 25 18:33:42 2018 +0000
@@ -0,0 +1,46 @@
+
+#include "mbed.h"
+
+enum State {READ_INPUT, WRITE_DISTANCE} state = READ_INPUT;
+
+Ticker timer;
+DigitalIn push_button(D15);
+InterruptIn reset_button(USER_BUTTON);
+PwmOut LED(D3);
+AnalogIn Distance(PA_1);
+
+Serial pc(USBTX, USBRX);
+
+void reset()
+{
+    state = READ_INPUT;
+}
+
+int main()
+{
+    LED = 0;
+    int a=0;
+    reset_button.rise(&reset);
+    enum State next_state = state;
+
+    while(1) {
+        switch(next_state) {
+            case READ_INPUT:
+
+                LED=Distance.read();
+                if(push_button == 1) {
+                    next_state = WRITE_DISTANCE;
+
+                }
+                break;
+
+            case WRITE_DISTANCE:
+                while (a<1) {
+                    pc.printf("De afstand is cm :%f\n\r",(1-Distance.read())*18);
+                    a++;
+                }
+                break;
+
+        }
+    }
+}
diff -r 000000000000 -r 4a7c5016ab03 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Apr 25 18:33:42 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/994bdf8177cb
\ No newline at end of file