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
STM Implementierung mit Klassen
#include "mbed.h" DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); // States //typedef enum {ST_EIN, ST_AUS, ST_ERROR, ST_STATE1} nextState; // alternativ const int ST_EIN = 0; const int ST_AUS = 1; const int ST_ERROR = 2; // ---------------- Event Klasse -------------------------- class SwEvent { InterruptIn _isr; bool _pressed; void _RisingISR(); public: SwEvent(PinName pin) : _isr(pin) { _pressed = false; } int CheckFlag(); // das muss im do-Zweig (while(true) Schleife) ständig abgefragt werden void InitIsr(); }; int SwEvent::CheckFlag() { if( _pressed ) { _pressed = false; return 1; } return 0; } void SwEvent::InitIsr() { _isr.rise(callback(this, &SwEvent::_RisingISR)); } void SwEvent::_RisingISR() { wait_ms(100); _pressed = true; } SwEvent sw1(p14); // Joy Stick Center // ----------------- Stm Klasse ----------------------------- class Stm { public: Stm() { state=ST_AUS; } void Ein(); void Aus(); void Error(); uint8_t state; }; void Stm::Ein(){ while(true) { led1 = 0; if(sw1.CheckFlag()) { state = ST_AUS; return; } } } void Stm::Aus(){ while(true) { led1 = 1; if(sw1.CheckFlag()) { state = ST_EIN; return; } } } void Stm::Error(){ while(1) { led3 = ~led3; wait_ms(200); } } Stm stm; void stateMachine() { printf("state: %d\n", stm.state); switch (stm.state) { case ST_EIN: stm.Ein(); break; case ST_AUS: stm.Aus(); break; default: stm.Error(); break; } } int main() { printf("Hello STM class\n"); sw1.InitIsr(); while(1) { stateMachine(); } }
Aufgabe:
Teilen Sie obigen Code auf die entsprechenden Include- und Source-Dateien auf. Sie werden wahrscheinlich Initalisierunglisten benötigen.