julian Roll
/
M0_Blinky_OOP
JA paner
main.cpp@0:e2682c264053, 2015-12-14 (annotated)
- Committer:
- Polteko123
- Date:
- Mon Dec 14 15:57:55 2015 +0000
- Revision:
- 0:e2682c264053
JA; paner
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Polteko123 | 0:e2682c264053 | 1 | #include "mbed.h" |
Polteko123 | 0:e2682c264053 | 2 | |
Polteko123 | 0:e2682c264053 | 3 | class MyLed |
Polteko123 | 0:e2682c264053 | 4 | { |
Polteko123 | 0:e2682c264053 | 5 | private: |
Polteko123 | 0:e2682c264053 | 6 | DigitalOut *led1; //Adresser des eigentlichen zieles - auf eine Klasse DigitalOut - erzeugen |
Polteko123 | 0:e2682c264053 | 7 | BusOut *Busled; |
Polteko123 | 0:e2682c264053 | 8 | MyLed(); //Standardkonstruktor, auf den von außen nicht zugegriffen werden kann |
Polteko123 | 0:e2682c264053 | 9 | |
Polteko123 | 0:e2682c264053 | 10 | |
Polteko123 | 0:e2682c264053 | 11 | |
Polteko123 | 0:e2682c264053 | 12 | |
Polteko123 | 0:e2682c264053 | 13 | public: |
Polteko123 | 0:e2682c264053 | 14 | //Parametrisierten konstruktor - selber Name wie Klasse - mit einem Pin Namen als Parameter |
Polteko123 | 0:e2682c264053 | 15 | MyLed(PinName ld1) :led1(&DigitalOut(ld1)) |
Polteko123 | 0:e2682c264053 | 16 | { |
Polteko123 | 0:e2682c264053 | 17 | //erzeugt ein neues Digitalout Objekt led1 mit Pin ld1 |
Polteko123 | 0:e2682c264053 | 18 | led1 = new DigitalOut(ld1); |
Polteko123 | 0:e2682c264053 | 19 | }; |
Polteko123 | 0:e2682c264053 | 20 | |
Polteko123 | 0:e2682c264053 | 21 | MyLed(PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8) : Busled(&BusOut(p1, p2, p3, p4, p5, p6, p7, p8)){ |
Polteko123 | 0:e2682c264053 | 22 | }; |
Polteko123 | 0:e2682c264053 | 23 | //Methoden oder Memberfunktion |
Polteko123 | 0:e2682c264053 | 24 | void LedOn(uint8_t a) |
Polteko123 | 0:e2682c264053 | 25 | { |
Polteko123 | 0:e2682c264053 | 26 | //Aufruf der Methode write() in der klasse DigitalOut --> üer den Zeiger led1 |
Polteko123 | 0:e2682c264053 | 27 | //(*led1).write(1); |
Polteko123 | 0:e2682c264053 | 28 | Busled->write(a); |
Polteko123 | 0:e2682c264053 | 29 | } |
Polteko123 | 0:e2682c264053 | 30 | void LedOff(uint8_t a) |
Polteko123 | 0:e2682c264053 | 31 | { |
Polteko123 | 0:e2682c264053 | 32 | Busled->write(0); |
Polteko123 | 0:e2682c264053 | 33 | } |
Polteko123 | 0:e2682c264053 | 34 | }; |
Polteko123 | 0:e2682c264053 | 35 | |
Polteko123 | 0:e2682c264053 | 36 | //DigitalOut myled(P1_8); |
Polteko123 | 0:e2682c264053 | 37 | |
Polteko123 | 0:e2682c264053 | 38 | int main() { |
Polteko123 | 0:e2682c264053 | 39 | MyLed myLedBus(P1_0, P1_1, P1_3, P1_4, P1_6, P1_7, P1_12, P1_13); |
Polteko123 | 0:e2682c264053 | 40 | int i = 0; |
Polteko123 | 0:e2682c264053 | 41 | |
Polteko123 | 0:e2682c264053 | 42 | while(1) |
Polteko123 | 0:e2682c264053 | 43 | { |
Polteko123 | 0:e2682c264053 | 44 | myLedBus.LedOn(i++); |
Polteko123 | 0:e2682c264053 | 45 | wait(0.2); |
Polteko123 | 0:e2682c264053 | 46 | myLedBus.LedOff(i++); |
Polteko123 | 0:e2682c264053 | 47 | wait(0.2); |
Polteko123 | 0:e2682c264053 | 48 | } |
Polteko123 | 0:e2682c264053 | 49 | |
Polteko123 | 0:e2682c264053 | 50 | } |