§BHELI / Mbed 2 deprecated Fahrradleuchte

Dependencies:   mbed

Revision:
0:63709874455b
Child:
1:4d500c8ba221
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Feb 23 14:24:41 2015 +0000
@@ -0,0 +1,115 @@
+#include "mbed.h"
+#include "BtnEventM0.h"
+
+BusOut lb(P1_7,P1_6,P1_4,P1_3,P1_1,P1_0,LED4,LED3,LED2,LED1);
+BusOut stLED(P1_13,P1_12);                                      
+
+BtnEventM0 Btn1(P0_15), Btn2(P0_23);
+
+class FahrradLeuchte {                          //Eine Klasse namens FahrradLeuchte
+    public:                                     //Öffentlich
+        void Init() { state=1; t1.start(); }    //Beim Aufrufen wird der Status auf 1 gesetzt und der Timer t1 gestartet
+        void State1Func();                      //Funktion definieren
+        void State2Func();                      //Funktion definieren
+        void State3Func();                      //Funktion definieren
+    public:                                     //Öffentlich
+        void State1Action();                    //Funktion definieren
+        void State2Action();                    //Funktion definieren
+        void State3Action();                    //Funktion definieren
+    public:                                     //Öffentlich
+        int state;                              //Integer state definieren
+        Timer t1;                               //Timer t1 definieren
+};
+
+FahrradLeuchte fl;                              //Klasse als Variabel aktivieren
+
+int main() {                                    //Main-Funktion
+    lb=0;                                       //Gesamte Ledbar auf 0 setzen
+    Btn1.Init(); Btn2.Init();                   //Btn1 und Btn2 mit Init ansprechen
+    fl.Init();
+    while(1)
+    {
+        if( fl.state==1 )
+            fl.State1Func();
+        if( fl.state==2 )
+            fl.State2Func();
+        if( fl.state==3 )
+            fl.State3Func();
+    }
+    
+}
+
+void FahrradLeuchte::State1Func()
+{
+    t1.reset();
+    stLED = 1;
+    while(1)
+    {
+        State1Action();
+        if( Btn1.CheckFlag() )
+            { state=2; return; }
+        if( Btn2.CheckFlag() )
+            { state=3; return; }
+    }
+}
+
+void FahrradLeuchte::State2Func()
+{
+    t1.reset();
+    stLED = 2;
+    while(1)
+    {
+        State2Action();
+        if( Btn1.CheckFlag() )
+            { state=3; return; }
+        if( Btn2.CheckFlag() )
+            { state=1; return; }
+    }
+}
+
+void FahrradLeuchte::State3Func()
+{
+    t1.reset();
+    stLED = 3;
+    while(1)
+    {
+        State3Action();
+        if( Btn1.CheckFlag() )
+            { state=1; return; }
+        if( Btn2.CheckFlag() )
+            { state=2; return; }
+    }
+}
+
+void FahrradLeuchte::State1Action()
+{
+    if( t1.read_ms()<500 )
+        return;
+    t1.reset();
+    if( lb==0 )
+        lb = 512;
+    else
+        lb = 0;
+}
+
+void FahrradLeuchte::State2Action()
+{
+    if( t1.read_ms()<200 )
+        return;
+    t1.reset();
+    if( lb==0 )
+        lb = 256;
+    else
+        lb = 0;
+}
+
+void FahrradLeuchte::State3Action()
+{
+    if( t1.read_ms()<100 )
+        return;
+    t1.reset();
+    if( lb==0 )
+        lb = 128;
+    else
+        lb = 0;
+}
\ No newline at end of file