Christian Weiß
/
TINF_TwoLEDs
TINF_TwoLeds_Bsp1
main.cpp
- Committer:
- Wizo
- Date:
- 2018-06-18
- Revision:
- 0:23f5cf9d9707
File content as of revision 0:23f5cf9d9707:
#include "mbed.h" class TwoLeds { public: TwoLeds(PinName pin1, PinName pin2) : _pin1(pin1), _pin2(pin2) { // Initialisierungsliste _pin1 = 0; // Initialisierung mit 0 _pin2 = 0; } void ledOn(void) { _pin1 = 1; _pin2 = 1; } void ledOff(void) { _pin1 = 0; _pin2 = 0; } void 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 printStatus(void) { printf("LED1 is now: %d\n", _pin1.read()); printf("LED2 is now: %d\n", _pin2.read()); } private: DigitalOut _pin1; DigitalOut _pin2; }; 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); } }