State Maschine Übungen von fPucher https://os.mbed.com/users/fpucher/code/HIM0Board/wiki/STM-Schalter

Dependencies:   mbed C12832

Revision:
1:fdfc2454217b
Parent:
0:7f1867e68546
Child:
2:7dafc3e72a72
--- a/main.cpp	Thu Nov 08 16:45:58 2018 +0000
+++ b/main.cpp	Thu Nov 08 18:01:57 2018 +0000
@@ -10,6 +10,9 @@
 InterruptIn  SW3(p12); 
 InterruptIn  SW4(p16); 
 
+Ticker T1;
+volatile int blinkCount = 0; 
+
 //************** LCD ****************
 
 C12832 lcd(p5, p7, p6, p8, p11);
@@ -21,6 +24,15 @@
 
 bool pressed = false;
 
+//************* andere Funktionen ****************
+
+void blink()
+{
+    blinkCount++;
+    
+    Led4 = !Led4;
+}
+
 
 //************* EREIGNISSE ****************
  
@@ -72,14 +84,13 @@
     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);
+    T1.attach(&blink, 0.3);
+    while (true)
+    {
+      if(blinkCount >= 4) break;
+    }
+    T1.detach();
+    blinkCount = 0;
     // do
     while(true) {
         Led1 = 1;