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
#include "mbed.h"
#include <Debouncer.h>
PwmOut led1(p36);
PwmOut green(p5);
PwmOut blue(p34);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
//DigitalIn taste(P0_10);
Debouncer butt(P0_10);
// 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) {
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);
}
}
void stateMachine()
{
switch (state)
{
case ST_EIN: ST_Ein();
break;
case ST_AUS: ST_Aus();
break;
default: ST_Error();
break;
}
}
int main()
{
printf("Hello STM\n");
butt.attach_fall(&fall); //.attach_rise(&rise);
blue=green=1;
while(1) {
stateMachine();
}
}