Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Code Klasse
#include "mbed.h"
 
class MyLed {
public:
// Konstruktor
    MyLed(PinName led) : _led(led) {    // Initalisierungsliste
        _led = 0;                       // 0 _led zuweisen
    }
// Methodenprototyping
    void ledOn(void);
    void ledOff(void);
    void printStatus(void);
 
private:
    DigitalOut _led;
};
 
// Methodendefinition
void MyLed::ledOn(void) {
    _led = 1;
}
 
void MyLed::ledOff(void) {
    _led = 0;
}
 
void MyLed::printStatus(void) {
    printf("LED is now: %d\n", _led.read());
}
 
MyLed myled2(LED2);         // Instanziierung des Objekts
 
int main() {
    while (1) {
        myled2.ledOn();     // Zugriff auf die Methode über "."-Operator
        myled2.printStatus();
        wait_ms(500);
        myled2.ledOff();
        myled2.printStatus();
        wait_ms(500);
    }
}