Ampel

Dependencies:   mbed

Fork of 2016-01-25_LABOR_Ampel by the new engineer´s

Files at this revision

API Documentation at this revision

Comitter:
tauchi88
Date:
Mon Jan 25 18:49:32 2016 +0000
Commit message:
ampel

Changed in this revision

Ampel.cpp Show annotated file Show diff for this revision Revisions of this file
BtnEventM0.h 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/Ampel.cpp	Mon Jan 25 18:49:32 2016 +0000
@@ -0,0 +1,94 @@
+#include "mbed.h"
+#include "BtnEventM0.h"
+
+//Ledbar
+BusOut  lb1(P1_7, P1_6, P1_4, P1_3, P1_1, P1_0, LED4, LED3, LED2, LED1);
+
+// Statusled zeigt uns in welchem Zustand ide Statmachine gerade ist
+BusOut stLED(P1_13, P1_12);
+
+//erledigt für uns die Abfrage der positiven Flange
+BtnEventM0 sw4(P1_16), sw3(P0_23);          //sw4 vorwärts  sw3 rückwärts
+
+Serial pc(USBTX, USBRX);
+
+const int St_Rot = 1;
+const int St_Gelb = 1;
+const int St_Gruen = 1;
+
+
+class Ampel
+{
+public:
+    void Init() {
+        state=St_Rot;
+        t1.start();
+        t2.start();
+        t3.start();
+    }
+    void Rot();
+    void Gelb();
+    void Gruen();
+public:
+    void RotAction();
+    void GelbAction();
+    void GruenAction();
+public:
+    int state;
+    Timer t1;   //blinken
+    Timer t2;   //mit 10 Hz zur anzeige schicken
+    Timer t3;   //Zeit bis zum umschalten anzeigen
+
+};
+
+Ampel amp;
+
+
+int main(void)
+{
+    amp.Init();
+    sw3.Init();
+    sw4.Init();
+    pc.baud(125000);
+
+
+    while(1) {
+
+    }
+}
+
+//-----------------------------------------------------------------------------------------------------
+
+void Ampel::Rot()
+{
+    //einmalige aktion
+    pc.printf("ROT\n");
+    t3.reset();
+    while(1) {
+        //Btn und Zeit abfragen (möglicher Zustandwechsel)
+        if(t3.read_ms()>3000) {
+            state=St_Gelb;
+            return;
+        }
+        RotAction();
+    }
+
+}
+
+void Ampel::RotAction()
+{
+    //Blinken
+    if(t1.read_ms()>500) {
+        t1.reset();
+        if(lb1==0)
+            lb1=1;       //bei Gelb soll dann lb=4
+        else
+            lb1 =0;
+    }
+    //RestZeit mit 10 Hz zur Anzeige senden
+    if(t2.read_ms()>100) {
+        t2.reset();
+        pc.printf("2 %d\n", t3.read_ms()/100);   //Zeitanzeige auf 1/10sec genau
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BtnEventM0.h	Mon Jan 25 18:49:32 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/mbed.bld	Mon Jan 25 18:49:32 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file