MBED_Afstandsmeter Niek
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:4a7c5016ab03
--- /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; + + } + } +}