Übungen zu Klassen 3BHEL

Dependencies:   mbed

Übungen zu Klassen 3BHEL

Erzeugen einer Bibliothek MyLed

Files at this revision

API Documentation at this revision

Comitter:
bulmecisco
Date:
Thu May 19 15:30:39 2016 +0000
Commit message:
?bungen zu Klassen 3BHEL

Changed in this revision

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 b098c8f91521 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 19 15:30:39 2016 +0000
@@ -0,0 +1,73 @@
+#include "mbed.h"
+
+//DigitalOut myled(LED1);
+
+class MyLed {
+    DigitalOut _led;
+public:
+    MyLed(PinName pin) :  _led(pin) { }
+    
+    void LedOn()  { _led = 1; } 
+    void LedOff() { _led = 0; }
+};
+
+// Bei drücken eines Tasters soll eine ISR aufgerufen werden
+// bool CheckFlag();  // soll true zurück geben, wenn eine Taste gedrückt wurde
+
+class Event {
+    InterruptIn _isr;
+    bool _pressed;
+public:
+    Event(PinName pin) : _isr(pin) {
+        _isr.rise(this, &Event::rise);
+        _pressed = false;
+    }
+        
+    void rise() {
+        _pressed = true;
+    }
+    
+    bool CheckFlag() {
+        if(_pressed) {
+            _pressed=false;
+            return true;
+        }
+        return false;
+    }
+};
+
+class RgbLed {
+    PwmOut _g;
+    PwmOut _b;
+    PwmOut _r;
+public:
+    RgbLed(PinName g, PinName b, PinName r) :  _g(g), _b(b), _r(r) { }
+    
+    void write(float g, float b, float r) {
+        _g = g;
+        _b = b;
+        _r = r;
+    }
+};
+
+MyLed myled2(LED1);
+MyLed myled3(LED3);
+RgbLed myled(P0_9, P1_15, P0_21); // g, b, r
+Event sw1(P0_10);
+
+int main() {
+    while(1) {
+        if(sw1.CheckFlag()) {
+            myled3.LedOn();
+            wait(0.5f);
+            myled3.LedOff();
+        }
+        
+        myled.write(0.1, 0.2, 0.3);
+        myled2.LedOn();
+        wait(0.2);
+        myled2.LedOff();
+        wait(0.2);
+
+    }
+}
diff -r 000000000000 -r b098c8f91521 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu May 19 15:30:39 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e
\ No newline at end of file