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 Schalter
STM SCHALTER¶
Das Zustandsdiagramm (Statechart Diagram) sieht folgendermaßen aus:
iSTM SCHALTER
#include "mbed.h" #include "C12832.h" DigitalOut Led1(LED1, 0); DigitalOut Led2(LED2, 0); DigitalOut Led3(LED3, 0); DigitalOut Led4(LED4, 0); InterruptIn SW1(p14); InterruptIn SW2(p15); InterruptIn SW3(p12); InterruptIn SW4(p16); C12832 lcd(p5, p7, p6, p8, p11); enum State {ST_AUS=0, ST_EIN}; State state; bool pressed = false; void rise(void) { wait_ms(100); pressed = true; } bool CheckFlag() { if (pressed) { pressed=false; return true; } return false; } void ST_Aus (void) { //Status auf LCD lcd.cls(); // clear screen lcd.locate(0,0); // x-position, y-position (x: 0-128; y: 0-32) lcd.printf("State: 1 (Aus)"); // entry // do while(true) { Led1 = 0; if(CheckFlag()) { state = ST_EIN; // exit return; } } } void ST_Ein (void) { //Status auf LCD lcd.cls(); // clear screen lcd.locate(0,0); // x-position, y-position (x: 0-128; y: 0-32) lcd.printf("State: 2 (Ein)"); // entry Led4 = 1; wait_ms(200); Led4 = 0; wait_ms(200); Led4 = 1; wait_ms(200); Led4 = 0; wait_ms(200); // do while(true) { Led1 = 1; if(CheckFlag()) { state = ST_AUS; // exit return; } } } void ST_Error (void) { //Status auf LCD lcd.cls(); // clear screen lcd.locate(0,0); // x-position, y-position (x: 0-128; y: 0-32) lcd.printf("State: ERROR"); return; } void stateMachine() { switch (state) { case ST_AUS: ST_Aus(); break; case ST_EIN: ST_Ein(); break; default: ST_Error(); // sollte nicht auftreten :-) break; } } int main() { SW1.rise(&rise); //.fall(&fall); state = ST_AUS; while(true){ stateMachine(); } }