Oliver Ainhirn
/
Pucher_Bsp_1
Beispiel1
main.cpp@0:57e2de37f8d5, 2019-02-04 (annotated)
- Committer:
- corsa1600
- Date:
- Mon Feb 04 16:49:52 2019 +0000
- Revision:
- 0:57e2de37f8d5
Beispiel1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
corsa1600 | 0:57e2de37f8d5 | 1 | #include "mbed.h" |
corsa1600 | 0:57e2de37f8d5 | 2 | |
corsa1600 | 0:57e2de37f8d5 | 3 | /********Beispiel 1********************* |
corsa1600 | 0:57e2de37f8d5 | 4 | ledOn() // beide Leds einschalten |
corsa1600 | 0:57e2de37f8d5 | 5 | ledOff() // beide Leds ausschalten |
corsa1600 | 0:57e2de37f8d5 | 6 | ledX() // beide Leds gegengleich schalten |
corsa1600 | 0:57e2de37f8d5 | 7 | printStatus() // Anzeigen ob Leds ein oder aus |
corsa1600 | 0:57e2de37f8d5 | 8 | ******************************/ |
corsa1600 | 0:57e2de37f8d5 | 9 | |
corsa1600 | 0:57e2de37f8d5 | 10 | |
corsa1600 | 0:57e2de37f8d5 | 11 | /**********Beispiel 2*********************** |
corsa1600 | 0:57e2de37f8d5 | 12 | * //lauflicht() |
corsa1600 | 0:57e2de37f8d5 | 13 | D1 D2 D3 D4 |
corsa1600 | 0:57e2de37f8d5 | 14 | - - - - Ein Durchgang dauert 2 sec |
corsa1600 | 0:57e2de37f8d5 | 15 | X - - - |
corsa1600 | 0:57e2de37f8d5 | 16 | - X - - |
corsa1600 | 0:57e2de37f8d5 | 17 | - - X - |
corsa1600 | 0:57e2de37f8d5 | 18 | - - - X |
corsa1600 | 0:57e2de37f8d5 | 19 | - - - - X=ON - = off |
corsa1600 | 0:57e2de37f8d5 | 20 | *********************************/ |
corsa1600 | 0:57e2de37f8d5 | 21 | |
corsa1600 | 0:57e2de37f8d5 | 22 | /***********Beispiel 3********************** |
corsa1600 | 0:57e2de37f8d5 | 23 | * //lauflichtbalken() |
corsa1600 | 0:57e2de37f8d5 | 24 | D1 D2 D3 D4 |
corsa1600 | 0:57e2de37f8d5 | 25 | - - - - Ein Durchgang dauert 2 sec |
corsa1600 | 0:57e2de37f8d5 | 26 | X - - - |
corsa1600 | 0:57e2de37f8d5 | 27 | X X - - |
corsa1600 | 0:57e2de37f8d5 | 28 | X X X - |
corsa1600 | 0:57e2de37f8d5 | 29 | X X X X |
corsa1600 | 0:57e2de37f8d5 | 30 | - - - - |
corsa1600 | 0:57e2de37f8d5 | 31 | X X X X X=ON - = off |
corsa1600 | 0:57e2de37f8d5 | 32 | **********************************/ |
corsa1600 | 0:57e2de37f8d5 | 33 | |
corsa1600 | 0:57e2de37f8d5 | 34 | class TwoLeds |
corsa1600 | 0:57e2de37f8d5 | 35 | { |
corsa1600 | 0:57e2de37f8d5 | 36 | public: |
corsa1600 | 0:57e2de37f8d5 | 37 | TwoLeds(PinName pin, PinName pin2 ) : _pin(pin) , _pin2(pin2) // initialisierungsliste ( muss gleich heissen wie der Konstruktor ) |
corsa1600 | 0:57e2de37f8d5 | 38 | { |
corsa1600 | 0:57e2de37f8d5 | 39 | _pin=0; // initalisierung mit 0 |
corsa1600 | 0:57e2de37f8d5 | 40 | _pin2=0; |
corsa1600 | 0:57e2de37f8d5 | 41 | } |
corsa1600 | 0:57e2de37f8d5 | 42 | |
corsa1600 | 0:57e2de37f8d5 | 43 | void ledOn(void) |
corsa1600 | 0:57e2de37f8d5 | 44 | { |
corsa1600 | 0:57e2de37f8d5 | 45 | _pin=1; |
corsa1600 | 0:57e2de37f8d5 | 46 | _pin2=1; |
corsa1600 | 0:57e2de37f8d5 | 47 | } |
corsa1600 | 0:57e2de37f8d5 | 48 | |
corsa1600 | 0:57e2de37f8d5 | 49 | void ledOff(void) |
corsa1600 | 0:57e2de37f8d5 | 50 | { |
corsa1600 | 0:57e2de37f8d5 | 51 | _pin=0; |
corsa1600 | 0:57e2de37f8d5 | 52 | _pin2=0; |
corsa1600 | 0:57e2de37f8d5 | 53 | } |
corsa1600 | 0:57e2de37f8d5 | 54 | void ledX(void) |
corsa1600 | 0:57e2de37f8d5 | 55 | { |
corsa1600 | 0:57e2de37f8d5 | 56 | if (_pin.read() == 1) |
corsa1600 | 0:57e2de37f8d5 | 57 | { |
corsa1600 | 0:57e2de37f8d5 | 58 | _pin= 0; |
corsa1600 | 0:57e2de37f8d5 | 59 | _pin2 =1; |
corsa1600 | 0:57e2de37f8d5 | 60 | } |
corsa1600 | 0:57e2de37f8d5 | 61 | else |
corsa1600 | 0:57e2de37f8d5 | 62 | { |
corsa1600 | 0:57e2de37f8d5 | 63 | |
corsa1600 | 0:57e2de37f8d5 | 64 | _pin= 1; |
corsa1600 | 0:57e2de37f8d5 | 65 | _pin2= 0; |
corsa1600 | 0:57e2de37f8d5 | 66 | } |
corsa1600 | 0:57e2de37f8d5 | 67 | } |
corsa1600 | 0:57e2de37f8d5 | 68 | |
corsa1600 | 0:57e2de37f8d5 | 69 | void printStatus(void) |
corsa1600 | 0:57e2de37f8d5 | 70 | { |
corsa1600 | 0:57e2de37f8d5 | 71 | printf("Status Read:\nLED1 is now %d\nLED2 is now %d\n\n", _pin.read(), _pin2.read()); |
corsa1600 | 0:57e2de37f8d5 | 72 | // printf("Read LED is now %d\n", _pin2.read()); |
corsa1600 | 0:57e2de37f8d5 | 73 | } |
corsa1600 | 0:57e2de37f8d5 | 74 | private: |
corsa1600 | 0:57e2de37f8d5 | 75 | DigitalOut _pin; // _steht im Namen für privat, am Anfang oder am ende |
corsa1600 | 0:57e2de37f8d5 | 76 | DigitalOut _pin2; |
corsa1600 | 0:57e2de37f8d5 | 77 | }; |
corsa1600 | 0:57e2de37f8d5 | 78 | |
corsa1600 | 0:57e2de37f8d5 | 79 | |
corsa1600 | 0:57e2de37f8d5 | 80 | TwoLeds twoleds(LED1, LED2); |
corsa1600 | 0:57e2de37f8d5 | 81 | //DigitalOut led(LED1); |
corsa1600 | 0:57e2de37f8d5 | 82 | /* MyLed myled1(LED1); |
corsa1600 | 0:57e2de37f8d5 | 83 | MyLed myled2(LED2); // Instanzierung des Objects |
corsa1600 | 0:57e2de37f8d5 | 84 | MyLed myled3(LED3); |
corsa1600 | 0:57e2de37f8d5 | 85 | MyLed myled4(LED4); |
corsa1600 | 0:57e2de37f8d5 | 86 | MyLed myled5(p5); |
corsa1600 | 0:57e2de37f8d5 | 87 | */ |
corsa1600 | 0:57e2de37f8d5 | 88 | |
corsa1600 | 0:57e2de37f8d5 | 89 | |
corsa1600 | 0:57e2de37f8d5 | 90 | |
corsa1600 | 0:57e2de37f8d5 | 91 | int main() |
corsa1600 | 0:57e2de37f8d5 | 92 | { |
corsa1600 | 0:57e2de37f8d5 | 93 | while (1) |
corsa1600 | 0:57e2de37f8d5 | 94 | { |
corsa1600 | 0:57e2de37f8d5 | 95 | |
corsa1600 | 0:57e2de37f8d5 | 96 | |
corsa1600 | 0:57e2de37f8d5 | 97 | |
corsa1600 | 0:57e2de37f8d5 | 98 | for ( int i=0; i<3; i++) |
corsa1600 | 0:57e2de37f8d5 | 99 | { |
corsa1600 | 0:57e2de37f8d5 | 100 | twoleds.ledOn(); // beide Leds einschalten |
corsa1600 | 0:57e2de37f8d5 | 101 | twoleds.printStatus(); // Anzeigen ob Leds ein oder aus |
corsa1600 | 0:57e2de37f8d5 | 102 | wait_ms(2000); |
corsa1600 | 0:57e2de37f8d5 | 103 | twoleds.ledOff(); // beide Leds ausschalten |
corsa1600 | 0:57e2de37f8d5 | 104 | twoleds.printStatus(); // Anzeigen ob Leds ein oder aus |
corsa1600 | 0:57e2de37f8d5 | 105 | wait_ms(2000); |
corsa1600 | 0:57e2de37f8d5 | 106 | } |
corsa1600 | 0:57e2de37f8d5 | 107 | for ( int i=0; i<5; i++) |
corsa1600 | 0:57e2de37f8d5 | 108 | { |
corsa1600 | 0:57e2de37f8d5 | 109 | twoleds.ledX(); // beide Leds gegengleich schalten |
corsa1600 | 0:57e2de37f8d5 | 110 | twoleds.printStatus(); // Anzeigen ob Leds ein oder aus |
corsa1600 | 0:57e2de37f8d5 | 111 | wait_ms(2000); |
corsa1600 | 0:57e2de37f8d5 | 112 | |
corsa1600 | 0:57e2de37f8d5 | 113 | } |
corsa1600 | 0:57e2de37f8d5 | 114 | |
corsa1600 | 0:57e2de37f8d5 | 115 | |
corsa1600 | 0:57e2de37f8d5 | 116 | } |
corsa1600 | 0:57e2de37f8d5 | 117 | } |
corsa1600 | 0:57e2de37f8d5 | 118 | |
corsa1600 | 0:57e2de37f8d5 | 119 | |
corsa1600 | 0:57e2de37f8d5 | 120 |