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.
You are viewing an older revision! See the latest version
Blinky Codes 1
Standard Blinky¶
aus mbed-Simulator
und Intro
Copy-Paste die folgenden Codes
#include "mbed.h" DigitalOut led(LED1); int main() { while (1) { led = !led; printf("Blink! LED is now %d\n", led.read()); wait_ms(500); } }
Blinky mit Klasse¶
#include "mbed.h" class Blinky { DigitalOut _myled; public: Blinky(PinName ld) : _myled(ld) {} void LedOn() { _myled = 1; } void LedOff() { _myled = 0; } int read() { return _myled.read(); } }; Blinky led(LED1); //DigitalOut led(LED1); int main() { printf("Blink LED is now %d\n", led.read()); while (1) { led.LedOn(); wait_ms(500); led.LedOff(); wait_ms(500); } }
Überladene Methode¶
#include "mbed.h" class Blinky { DigitalOut _myled; public: Blinky(PinName ld) : _myled(ld) {} void LedOn() { _myled = 1; } // überladene Methode LedOn void LedOn(int wert) { _myled = wert; } void LedOff() { _myled = 0; } int read() { return _myled.read(); } }; Blinky led(LED1); int main() { printf("Blink LED is now %d\n", led.read()); while (1) { led.LedOn(1); wait_ms(500); led.LedOff(); wait_ms(500); } }
Überladener Konstruktor¶
#include "mbed.h" class Blinky { DigitalOut _myled; public: Blinky() : _myled(LED1) {} // Standardkonstruktor Blinky(PinName ld) : _myled(ld) {} // überladener Konstruktor void LedOn() { _myled = 1; } // überladene Methode LedOn void LedOn(int wert) { _myled = wert; } void LedOff() { _myled = 0; } int read() { return _myled.read(); } }; //Blinky led(LED1); // Konstruktor mit LED-Pin als Argument Blinky led; // Aufruf Standardkonstruktor int main() { printf("Blink LED is now %d\n", led.read()); while (1) { led.LedOn(1); wait_ms(500); led.LedOff(); wait_ms(500); } }
Deklaration¶
Diskussion Deklaration versus Definition