abc

Dependencies:   C12832 mbed

Files at this revision

API Documentation at this revision

Comitter:
Reichi19
Date:
Thu Nov 15 17:18:16 2018 +0000
Parent:
0:f4216e9ad3a4
Commit message:
STM Schalter

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f4216e9ad3a4 -r 8c028fd2f964 main.cpp
--- a/main.cpp	Thu Oct 25 18:03:19 2018 +0000
+++ b/main.cpp	Thu Nov 15 17:18:16 2018 +0000
@@ -10,119 +10,81 @@
 InterruptIn  SW3(p12); 
 InterruptIn  SW4(p16); 
 
-//***** LCD *******
-
-C12832 lcd(p5, p7, p6, p8, p11);
-
-//***** VARIABLEN ******
-
-enum State {ST_AUS=0, ST_EIN};
-State state;
+//typedef enum {ST_EIN, ST_AUS, ST_STATE2, ST_STATE3} nextState;
+enum nextState {ST_EIN=0, ST_AUS, ST_STATE2, ST_STATE3};
+nextState state;
+// alternativ
+//const int ST_EIN = 0;
+//const int ST_AUS = 1;
+ 
+//uint8_t state = ST_AUS;
 
 bool pressed = false;
-
-
-//***** EREIGNISSE ******
+ 
+void fall(void) { 
+    wait_ms(20);
+    pressed = true; 
+}
  
-void rise(void)
-{  
-    wait_ms(50);
-    pressed = true;
-}
-
-bool CheckFlag() 
+bool CheckFlag()
 {
-    if (pressed) {
-        pressed=false;
-        return true;
-        }
+    if( pressed ) { 
+        pressed=false; 
+        return true; 
+    }
     return false;
 }
 
-//***** STATES ******
-
-void ST_Aus (void)
-{
-    //Status auf LCD
-    lcd.cls();      // löscht lcd (clear screen)
-    lcd.locate(0,0);   // x-position, y-position (x: 0-128; y: 0-32)
-    lcd.printf("State: 1 (Aus)");
+void ST_Ein(){
     // entry
-    
-    // do
-    while(true) {
-        Led1 = 0;
-    
-        if(CheckFlag()) {
-            state = ST_EIN;
-            
-    // exit
-            return;
-            }
-        }
-}
-
-void ST_Ein (void)
-{
-    //Status auf LCD
-    lcd.cls();      // löscht lcd (clear screen)
-    lcd.locate(0,0);   // x-position, y-position (x: 0-128; y: 0-32)
-    lcd.printf("State: 2 (Ein)");
-    
-    // entry
-    Led4 = 1;
-    wait_ms(200);
-    Led4 = 0;
-    wait_ms(200);
-    Led4 = 1;
-    wait_ms(200);
-    Led4 = 0;
-    wait_ms(200);
     // do
     while(true) {
         Led1 = 1;
-    
         if(CheckFlag()) {
             state = ST_AUS;
-            
-    // exit
+            // exit
             return;
-            }
         }
-    
+    }
 }
-
-void ST_Error (void)
-{
-    //Status auf LCD
-    lcd.cls();      // löscht lcd (clear screen)
-    lcd.locate(0,0);   // x-position, y-position (x: 0-128; y: 0-32)
-    lcd.printf("State: ERROR");
-    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;
-    case ST_EIN: ST_Ein();
-        break;
-    default: ST_Error();  // sollte nicht auftreten :-)
+    default: ST_Error();
         break;
     }
 }
 
 
- 
 int main()
 {
-    SW1.rise(&rise);      //.fall(&fall);
-    state = ST_AUS;
-    while(true){
+    printf("Hello STM\n");
+    SW1.fall(&fall); //.rise(&rise);
+    
+    while(1) {
         stateMachine(); 
-        }
-    
-    
+    }
 }
\ No newline at end of file