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 Funktionen
Definitionen
#include "mbed.h" DigitalOut Led1(LED1); DigitalOut Led2(LED2); DigitalOut Led3(LED3); DigitalOut Led4(LED4); InterruptIn SW1(p14);
States
//typedef enum {ST_EIN, ST_AUS, ST_STATE2, ST_STATE3} nextState; enum nextState {ST_EIN=0, ST_AUS, ST_STATE2, ST_STATE3}; nextState state; // alternativ //const int ST_EIN = 0; //const int ST_AUS = 1; //uint8_t state = ST_AUS;
Transitions
bool pressed = false; void fall(void) { wait_ms(20); pressed = true; } bool CheckFlag() { if( pressed ) { pressed=false; return true; } return false; }
State Functions
void ST_Ein(){ // entry // do while(true) { Led1 = 1; if(CheckFlag()) { state = ST_AUS; // exit return; } } } void ST_Aus(void){ while(true) { Led1 = 0; if(CheckFlag()) { state = ST_EIN; return; } } } void ST_Error(){ while(1) { Led3 = !Led3; wait_ms(200); } }
State Machine
void stateMachine() { switch (state) { case ST_EIN: ST_Ein(); break; case ST_AUS: ST_Aus(); break; default: ST_Error(); break; } }
Main
int main() { printf("Hello STM\n"); SW1.fall(&fall); //.rise(&rise); while(1) { stateMachine(); } }