TwoLeds
Revision 0:047ba38fb71d, committed 2018-06-20
- Comitter:
- Wizo
- Date:
- Wed Jun 20 15:38:58 2018 +0000
- Commit message:
- Two Leds
Changed in this revision
diff -r 000000000000 -r 047ba38fb71d TwoLeds.cpp --- /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
diff -r 000000000000 -r 047ba38fb71d TwoLeds.h --- /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
diff -r 000000000000 -r 047ba38fb71d main.cpp --- /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