State Machine Taster EIN AUS

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
franzpaulus
Date:
Thu Nov 08 18:27:24 2018 +0000
Commit message:
State Machine Taster EIN AUS

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 08 18:27:24 2018 +0000
@@ -0,0 +1,75 @@
+#include "mbed.h"
+
+DigitalOut Led1(LED1);
+DigitalOut Led2(LED2);
+DigitalOut Led3(LED3);
+DigitalOut Led4(LED4);
+InterruptIn  SW1(p14);
+
+enum nextState {ST_EIN=0, ST_AUS, ST_STATE2, ST_STATE3};
+nextState state;
+
+bool pressed = false;
+ 
+void fall(void) { 
+    wait_ms(20);
+    pressed = true; 
+}
+ 
+bool CheckFlag()
+{
+    if( pressed ) { 
+        pressed=false; 
+        return true; 
+    }
+    return false;
+}
+
+void ST_Ein(){
+    while(true) {
+        Led1 = 1;
+        if(CheckFlag()) {
+            state = ST_AUS;
+            return;
+        }
+    }
+}
+ 
+void ST_Aus(void){
+    while(true) {
+        Led1 = 0;
+        if(CheckFlag()) {
+            state = ST_EIN;
+            return;
+        }
+    }
+}
+ 
+void ST_Error(){
+    while(1) {
+        Led3 = !Led3;
+        wait_ms(200);
+    }
+}
+
+void stateMachine()
+{
+    switch (state)
+    {
+    case ST_EIN: ST_Ein();
+        break;
+    case ST_AUS: ST_Aus();
+        break;
+    default: ST_Error();
+        break;
+    }
+}
+
+int main()
+{
+    printf("Hello STM\n");
+    SW1.fall(&fall); //.rise(&rise);
+    while(1) {
+        stateMachine(); 
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Nov 08 18:27:24 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file