Fahrradleuchte

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
david22
Date:
Wed Nov 16 10:58:26 2016 +0000
Commit message:
Richtiges Projekt f?r 3CHEL

Changed in this revision

BtnEventM0.h Show annotated file Show diff for this revision Revisions of this file
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/BtnEventM0.h	Wed Nov 16 10:58:26 2016 +0000
@@ -0,0 +1,146 @@
+
+
+class BtnEventM0
+{
+public:
+    int16_t pressed;
+
+    BtnEventM0(PinName pin) : _isr(pin) {
+        pressed=0;
+    }
+
+    // Ist eine steigende Flanke aufgetreten ?
+    int CheckFlag() {
+        if( pressed ) {
+            pressed=0;
+            return 1;
+        }
+        return 0;
+    }
+
+    // 1..Button is pressed  else 0
+    int CheckButton() {
+        return _isr.read();
+    }
+
+    void Init() {
+        _isr.rise(this, &BtnEventM0::RisingISR);
+    }
+
+    void RisingISR() {
+        if( _isr.read() )
+            pressed = 1;
+    }
+protected:
+    InterruptIn _isr;
+};
+
+/*
+class BtnEventM02 : public BtnEventM0
+{
+public:
+    BtnEventM02(PinName pin) : BtnEventM0(pin) {
+        _tm.stop();
+        _tm.reset();
+        _state=1;
+    }
+
+    void Init() {
+        _isr.rise(this, &BtnEventM02::RisingISR);
+    }
+
+    void RisingISR() {
+        if( !_isr.read() )
+            return;
+        pressed = 1;
+        _tm.start();
+        _state = 2;
+    }
+
+    void CheckButton() {
+        if( _state==1 )
+            return;
+        if( _state==2 ) {
+            if( !_isr.read() ) {
+                _state = 1;
+                return;
+            }
+            if( _tm.read_ms()>500 ) {
+                _tm.reset();
+                _state = 3;
+                pressed = 1;
+            }
+        } else if( _state==3 ) {
+            if( !_isr.read() ) {
+                _state = 1;
+                return;
+            }
+            if( _tm.read_ms()>100 ) {
+                _tm.reset();
+                _state = 3;
+                pressed = 1;
+            }
+        }
+    }
+private:
+    int16_t _state;
+    Timer _tm;
+};
+*/
+
+class AnalogInHL : public AnalogIn
+{
+public:
+    AnalogInHL(PinName pin) : AnalogIn(pin) { }
+    int Read() {
+        return read_u16()>>6;
+    }
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 16 10:58:26 2016 +0000
@@ -0,0 +1,87 @@
+#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 sw4(P1_16), sw3(P0_23);
+
+
+class Fahrradleuchte{
+    public:
+        void Init()
+        {
+            state=1; t1.start();    
+        }
+        void State1Func();
+        void State2Func();
+        void State3Func();
+    public:
+        void State1Action(); // Bit0 (LED) mit 10Hz blinken 
+        void State2Action(); // Bit2 (LED) mit 5Hz blinken
+        void State3Action(); // Bit3 (LED) mit 2Hz blinken
+    public:
+        int state; // State sagt uns in welchem Zustand sich die Fahrradleuchte gerade befindet
+        Timer t1;
+};
+
+// Ein Objekt Fahrradleuchte anlegen
+Fahrradleuchte fl;
+
+int main(void)
+{
+     sw3.Init(); sw4.Init();
+     lb=0;  
+     while(1)
+     {
+        if(fl.state==1)
+        {fl.State1Func();}
+        if(fl.state==2)
+        {fl.State2Func();}   
+        if(fl.state==3)
+        {fl.State3Func();}       
+     } 
+}
+
+void Fahrradleuchte::State1Func()
+{
+    // Einmalige Aktion die beim Eintrit in die Funktion nötig sind
+    stLED=1;
+    
+    //
+    
+    while(1)
+    {
+         State1Action();
+         if(sw4.CheckFlag() ) // Btn's abfragen und möglicherweise Zustand ändern
+         {
+            state=2;
+            return;    
+         }   
+         if(sw3.CheckFlag() )
+         {
+            state=3; return;    
+         }
+    }
+}
+
+void Fahrradleuchte::State1Action()
+{
+    if(t1.read_ms()>100)
+    {
+        t1.reset();
+        if(lb==0)
+            lb= 1; // Mit Bit0 blinken 
+        else
+            lb=0;
+    }    
+}
+
+void Fahrradleuchte::State2Func()
+{
+    
+}
+
+void Fahrradleuchte::State3Func()
+{
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 16 10:58:26 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file