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.
main.cpp
- Committer:
- mexx
- Date:
- 2018-11-29
- Revision:
- 1:fb317288084d
- Parent:
- 0:ee837830d039
- Child:
- 2:73177929c8b4
File content as of revision 1:fb317288084d:
#include "mbed.h"
BusOut allLeds(LED1, LED2, LED3, LED4);
BusOut zweiLeds(LED1, LED2);
//DigitalOut led1(LED1);
//DigitalOut led2(LED2);
//DigitalOut led3(LED3);
//DigitalOut led4(LED4);
DigitalIn btn(P14);
enum Status {ST_LEDOFF=0, ST_LEDEIN=1,};
Status volatile status;
// States
//typedef enum {ST_EIN, ST_AUS, ST_ERROR, ST_STATE1} nextState;
// alternativ
//const int ST_EIN = 0;
//const int ST_AUS = 1;
//onst 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_LEDEIN: stm.Ein();
break;
case ST_LEDOFF: stm.Aus();
break;
default: stm.Error();
break;
}
}
int main()
{
printf("Hello STM class\n");
sw1.InitIsr();
while(1) {
stateMachine();
}
}