lalalala

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
DoTTi
Date:
Thu Dec 07 10:01:15 2017 +0000
Commit message:
llalal;

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
diff -r 000000000000 -r 1285025ec711 BtnEventM0.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BtnEventM0.h	Thu Dec 07 10:01:15 2017 +0000
@@ -0,0 +1,126 @@
+
+// V4.0
+
+class BtnEventM0 {
+    public:
+        int16_t pressed;
+        
+        BtnEventM0(PinName pin) : _isr(pin)
+            { pressed=0; }
+
+        // Ist eine steigende Flanke aufgetreten ?
+        int CheckFlag();
+    
+    // 1..Button is pressed  else 0
+        int CheckButton()
+            { return _isr.read(); }
+        
+        void Init();
+            // { _isr.rise(this,&BtnEventM0::RisingISR); }
+
+        void RisingISR();
+        
+    protected:
+        InterruptIn _isr;
+};
+
+void BtnEventM0::Init()
+            { _isr.rise(this,&BtnEventM0::RisingISR); }
+
+void BtnEventM0::RisingISR()
+{
+    if( _isr.read() )
+        pressed = 1;
+}
+
+int BtnEventM0::CheckFlag()
+{
+  if( pressed )
+      { pressed=0; return 1; }
+  return 0;
+}
+
+
+
+
+
+/*
+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;
+    }
+};
+
+class BtnEventM0S {
+    public:
+    BtnEventM0S(PinName pin) : _btn(pin) { }
+
+    void Init() {}
+
+        // Ist eine steigende Flanke aufgetreten ?
+        int CheckFlag()
+    {
+      if( _btn )
+        { wait_ms(100); return 1; }
+      else
+        return 0;
+    }
+
+  protected:
+        DigitalIn _btn;
+};
\ No newline at end of file
diff -r 000000000000 -r 1285025ec711 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 07 10:01:15 2017 +0000
@@ -0,0 +1,160 @@
+#include "mbed.h"
+#include "BtnEventM0.h"
+
+//        LSB                                                      MSB
+//        2^0   2^1   2^2                                          2^11
+BusOut lb(P1_7,P1_6,P1_4,P1_3,P1_1,P1_0,LED4,LED3,LED2,LED1);
+//        D20   D19   D18  D17  D16  D15  D14  D13  D4   D3   D2   D1
+
+// Zustandsangebe
+BusOut stLED(P1_13,P1_12);
+
+//        Sw3    Sw4
+BtnEventM0 sw3(P0_23), sw4(P1_16); //sw4 ist Fußgängerknopf
+
+Serial pc (USBTX, USBRX);
+
+class Ampel {
+    public:
+        void Init();
+        void rot_func();
+        void gelb_func();
+        void gruen_func();
+        void gruen_blink_func();
+    private:
+        void rot_act();
+        void gelb_act();
+        void gruen_act();
+        void gruen_blink_act();
+    public:
+        Timer t1, t2, t3;
+        int state;
+};
+
+const int st_rot = 1;
+const int st_gelb = 2;
+const int st_gruen = 3;
+const int st_gruen_blink = 4;
+
+Ampel amp;
+
+main() {
+    while(1) {
+        if(amp.state == 1)
+            amp.rot_func();
+        if(amp.state == 2)
+            amp.gelb_func();
+        if(amp.state == 3)
+            amp.gruen_func();
+        if(amp.state == 4)
+            amp.gruen_blink_func();
+    }
+}
+
+void Ampel::Init() {
+    t1.start();
+    t2.start();
+    t3.start();
+    
+    state = st_rot;
+}
+
+void Ampel::rot_func() {
+    stLED = 1;
+    
+    while(1) {
+        rot_act();
+        
+        if(t1.read_ms()>3000) {
+            t1.reset();
+            state = st_gelb;
+            return;
+        }
+    }
+}
+
+void Ampel::gelb_func() {
+    stLED = 2;
+    
+    while(1) {
+        gelb_act();
+        
+        if(t1.read_ms()>4000) {
+            t1.reset();
+            state = st_gruen;
+            return;
+        }
+        if(sw4.CheckFlag()) {
+            state = st_gruen_blink;
+            return;
+        }
+    }
+}
+
+void Ampel::gruen_func() {
+    stLED = 3;
+    
+    while(1) {
+        gruen_act();
+        
+        if(t1.read_ms()>5000) {
+            t1.reset();
+            state = st_rot;
+            return;
+        }
+        if(sw4.CheckFlag()) {
+            state = st_gruen_blink;
+            return;
+        }
+    }
+}
+
+void Ampel::gruen_blink_func() {
+    stLED = 4;
+    
+    while(1) {
+        gruen_blink_act();
+        
+        if(t1.read_ms()>2000) {
+            t1.reset();
+            state = st_rot;
+            return;
+        }
+    }
+}
+
+void Ampel::rot_act() {
+    if(t2.read_ms()>100) {
+        if(lb = 0)
+            lb = 2;
+        else
+            lb = 0;
+    }
+}
+
+void Ampel::gelb_act() {
+    if(t2.read_ms()>200) {
+        if(lb = 0)
+            lb = 4;
+        else
+            lb = 0;
+    }
+}
+
+void Ampel::gruen_act() {
+    if(t2.read_ms()>500) {
+        if(lb = 0)
+            lb = 8;
+        else
+            lb = 0;
+    }
+}
+
+void Ampel::gruen_blink_act() {
+    if(t2.read_ms()>700) {
+        if(lb = 0)
+            lb = 16;
+        else
+            lb = 0;
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 1285025ec711 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 07 10:01:15 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b484a57bc302
\ No newline at end of file