TwoLeds

Files at this revision

API Documentation at this revision

Comitter:
Wizo
Date:
Wed Jun 20 15:38:58 2018 +0000
Commit message:
Two Leds

Changed in this revision

TwoLeds.cpp Show annotated file Show diff for this revision Revisions of this file
TwoLeds.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TwoLeds.cpp	Wed Jun 20 15:38:58 2018 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+#include "TwoLeds.h"
+
+
+void TwoLeds::ledOn(void) {
+    _pin1 = 1;
+    _pin2 = 1;
+}
+
+void TwoLeds::ledOff(void) {
+    _pin1 = 0;
+    _pin2 = 0;
+}
+
+void TwoLeds::ledX() {
+    if( _pin1 == 0 && _pin2 == 0){
+        _pin1 = 1;
+        _pin2 = 0;
+    }
+    else if(_pin1 == 1 && _pin2 == 0){
+        _pin1 = 0;
+        _pin2 = 1;
+    }
+    else if(_pin1 == 0 && _pin2 == 1){
+        _pin1 = 1;
+        _pin2 = 0;
+    }
+
+}
+
+void TwoLeds::printStatus(void) {
+    printf("LED1 is now: %d\n", _pin1.read());
+    printf("LED2 is now: %d\n", _pin2.read());
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TwoLeds.h	Wed Jun 20 15:38:58 2018 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+#ifndef TWOLEDS_H
+#define TWOLEDS_H
+
+class TwoLeds
+{
+public:
+    TwoLeds(PinName pin1, PinName pin2) : _pin1(pin1), _pin2(pin2) {     // Initialisierungsliste
+        _pin1 = 0;                            // Initialisierung mit 0
+        _pin2 = 0;
+    }
+
+    void ledOn(void);
+
+    void ledOff(void); 
+
+    void ledX();
+
+    void printStatus(void);
+
+private:
+    DigitalOut _pin1;
+    DigitalOut _pin2;
+
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jun 20 15:38:58 2018 +0000
@@ -0,0 +1,25 @@
+#include "mbed.h"
+#include "TwoLeds.h"
+
+
+DigitalOut led(LED1);
+// MyLed myled2(LED2);                 // Instanziierung des Objektes
+// MyLed myled5(p5);
+
+TwoLeds twoleds(LED1, LED2);
+
+int main() {
+    while (1) {
+        /*twoleds.ledOn();             // Zugriff auf die Methode über "."-Operator
+        twoleds.printStatus();
+        wait_ms(500);
+        twoleds.ledOff();            // Zugriff auf die Methode über "."-Operator
+        twoleds.printStatus();
+        wait_ms(500); */
+        twoleds.ledX();
+        twoleds.printStatus();
+        wait_ms(500);
+        
+
+    }
+}
\ No newline at end of file