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.
Event Klasse
Der folgende Code zeigt die Interrupt-gesteuerte Switch-Klasse für die Taster am M0Board.
#include "mbed.h" #ifndef SWEVENT_H #define SWEVENT_H // ---------------- Switch Event Class -------------------------- class SwEvent { InterruptIn _isr; volatile int16_t _pressed; void _risingISR(); public: SwEvent(PinName pin) : _isr(pin) { // create the InterruptIn on the pin specified to SwEvent _isr.rise(this, &SwEvent::_risingISR); // attach ISR-function of this SwEvent instance _pressed=0; } int checkFlag(); // must in do-condition (while(true)-loop) continuously interrogated void init(); }; // ---------------- Switch Event Class Methodes -------------------------- int SwEvent::checkFlag() { if( _pressed ) { _pressed = 0; return 1; } return 0; } void SwEvent::_risingISR() { if( _isr.read() ) _pressed = 1; } #endif SwEvent sw1(p14);
In Zeile 34 wird beispielhaft für z.B. den Joy Stick Pins (center) das Objekt sw1 instanziiert.