Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
anti2810
Date:
Mon Mar 02 15:05:15 2015 +0000
Commit message:
Hallo hei morgeeeen;

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	Mon Mar 02 15:05:15 2015 +0000
@@ -0,0 +1,144 @@
+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	Mon Mar 02 15:05:15 2015 +0000
@@ -0,0 +1,141 @@
+#include "mbed.h"
+#include "BtnEventM0.h"
+
+BusOut lb(LED3,LED2,LED1);                                                          //Kleine Ledbar (In Verwendung)
+PwmOut g(p5), b(p34), r(p36);
+
+BusOut lbrest(P1_13,P1_12,P1_7,P1_6,P1_4,P1_3,P1_1,P1_0,LED4);                      //Rest der ausgeschalten wird (Standardmäßig auf 1)
+
+BtnEventM0 Btn1(P0_15);                                                             //Button zum Reseten
+
+class Ampel                                                                         //Ampelklasse
+{
+public:
+    void Init() {
+        state=1;
+        t1.start();
+        t2.start();
+        t3.start();
+    }
+    void Rot();                                                                 //Funktion Rot
+    void Gelb();                                                                //Funktion Gelb
+    void Gruen();                                                               //Funktion Grün
+public:
+    void RotAction();                                                           //Action Rot
+    void GelbAction();                                                          //Action Gelb
+    void GruenAction();                                                         //Action Gruen
+public:
+    int state;                                                                  //Statusvariabel
+    Timer t1, t2, t3;                                                           //Timer t1, t2 und t3
+};
+
+Ampel amp;                                                                          //Ampelklasse als Variabel aktivieren
+
+int main()                                                                          //Hauptfunktion
+{
+    lb=0;                                                                           //Ledbar auf 0 setzen
+    g=255;
+    b=255;
+    r=255;
+    lbrest=0;                                                                       //Ledbar auf 0 setzen
+    Btn1.Init();                                                                    //Button mit Funktion Init ansprechen
+    amp.Init();                                                                     //Ampelvariabel mit Funktion Init ansprechen
+    while(1) {                                                                      //Solange die Funktion aufgerufen wird
+        if( amp.state==1 )                                                          //Funktion auf state abstimmen
+            amp.Rot();
+        if( amp.state==2 )
+            amp.Gelb();
+        if( amp.state==3 )
+            amp.Gruen();
+        if( amp.state==4 )
+            amp.Gelb();
+    }
+}
+
+void Ampel::Rot()                                                                   //Funktion der Klasse Ampel
+{
+    t1.reset();                                                                     //Reseten
+    t2.reset();                                                                     //Reseten
+    t3.reset();                                                                     //Reseten
+    while(1) {
+        RotAction();                                                                //RotAction aufrufen
+        if( Btn1.CheckFlag() ) {                                                    //Bei einem Buttonclick
+            state=1;    //state = 1
+            return;
+        }
+    }
+}
+
+void Ampel::Gelb()                                                                  //Funktion der Klasse Ampel
+{
+    t1.reset();                                                                     //Reseten
+    t2.reset();                                                                     //Reseten
+    t3.reset();                                                                     //Reseten
+    while(1) {
+        GelbAction();                                                               //GelbAction aufrufen
+        if( Btn1.CheckFlag() ) {                                                    //Bei einem Buttonclick
+            state=1;    //state = 1
+            Rot();
+            return;
+        }
+    }
+}
+
+void Ampel::Gruen()                                                                 //Funktion der Klasse Ampel
+{
+    t1.reset();                                                                     //Reseten
+    t2.reset();                                                                     //Reseten
+    t3.reset();                                                                     //Reseten
+    while(1) {
+        GruenAction();                                                              //GruenAction aufrufen
+        if( Btn1.CheckFlag() ) {                                                    //Bei einem Buttonclick
+            state=1;    //state = 1
+            Rot();
+            return;
+        }
+    }
+}
+
+void Ampel::RotAction()                                                             //Funktion der Klasse Ampel
+{
+    if( t1.read_ms()<3000 ) {                                                       //Solange der Timer unter 3 Sekunden ist
+        lb=1;
+        g=255;
+        b=255;
+        r=0;                                                                       //Ledbar auf 1
+        return;                                                                     //Funktionsabbruch
+    }
+    state=2;                                                                        //state = 2
+    Gelb();                                                                         //Funktion Gelb aufrufen
+}
+
+void Ampel::GelbAction()                                                            //Funktion der Klasse Ampel
+{
+    if( t2.read_ms()<1000 ) {                                                       //Solange der Timer unter 1 Sekunden ist
+        lb=2;
+        g=0;
+        b=255;
+        r=0;                                                                        //Ledbar auf 2
+        return;                                                                     //Funktionsabbruch
+    }
+    if(state==2) {
+        state=3;                                                                    //state = 3
+        Gruen();                                                                    //Funktion Gruen aufrufen
+    } else {
+        state=1;                                                                    //state = 1
+        Rot();                                                                      //Funktion Rot aufrufen
+    }
+}
+
+void Ampel::GruenAction()                                                           //Funktion der Klasse Ampel
+{
+    if( t3.read_ms()<3000 ) {                                                       //Solange der Timer unter 3 Sekunden ist
+        lb=4;
+        g=0;
+        b=255;
+        r=255;                                                                        //Ledbar auf 4
+        return;                                                                     //Funktionsabbruch
+    }
+    state=4;                                                                        //state = 4
+    Gelb();                                                                         //Funktion Gelb aufrufen
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 02 15:05:15 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac
\ No newline at end of file