Domenic Ferlin
/
1_Test_TINF_29112018
Erste Zeilen
Revision 2:67791cb581e3, committed 2018-11-29
- Comitter:
- domenicf
- Date:
- Thu Nov 29 18:32:04 2018 +0000
- Parent:
- 1:05ce05a0f947
- Commit message:
- Fertig ohne doubleclick
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 05ce05a0f947 -r 67791cb581e3 main.cpp --- a/main.cpp Thu Nov 29 17:24:43 2018 +0000 +++ b/main.cpp Thu Nov 29 18:32:04 2018 +0000 @@ -1,21 +1,109 @@ #include "mbed.h" -class IsA : BusOut{ - - IsA():BusOut(LED1, LED2, LED3, LED4){}; - - void LedOff(){write(0x00);} +InterruptIn SW1(p14); + +BusOut Leds ( LED1 , LED2, LED3, LED4); + +Ticker flipper; + +enum State {ST_EIN=0, ST_AUS}; +State state; + +int LedWert = 3, btnCount = 0; + +bool pressed = false; + + + +void rise(void) +{ + wait_ms(50); + pressed = true; +} +bool CheckFlag() +{ + if (pressed) + { + pressed=false; + return true; + } + return false; +} + +void ST_Ein (void) +{ + + printf("State: EIN"); + + while(true) + { + Leds = LedWert; - void LedOn(int lVal){write(lVal)}; - void LedOn(){write(0x0f);} + if(CheckFlag()) + { + btnCount++; + if(btnCount >= 3) + { + btnCount = 0; + LedWert++; + state = ST_AUS; + + + return; + } + } + } +} +void ST_Aus (void) +{ + printf("State: AUS"); + while(true) { + Leds = 0; + if(CheckFlag()) + { + state = ST_EIN; + return; + } + } +} +void ST_Error (void) +{ + printf("State: ERROR!!!"); + return; +} + +void stateMachine() +{ + switch (state) + { + case ST_EIN: ST_Ein(); + break; + case ST_AUS: ST_Aus(); + break; + default: ST_Error(); + break; + } +} + +int main() +{ + SW1.rise(&rise); + Leds = 15; + wait_ms(500); - }; - + state = ST_EIN; + while(true) + { + stateMachine(); + } +} +///////// Funktioniert bei mir nicht, gibt immer wieder eine fehlermeldung vom SuperMain aus! +/* class IsAnEvent : public InterruptIn { volatile int16_t _pressed; void _RisingISR(); public: - IsAnEvent() : InterruptIn(p15) {}; + IsAnEvent() : InterruptIn(p14) {}; IsAnEvent(PinName pin) : InterruptIn(pin) { rise(callback(this, &IsAnEvent::_RisingISR)); _pressed=0; @@ -40,12 +128,4 @@ } return 0; } - -int main() { - - enum STM {INIT, EIN, AUS }; - - while(1) { - - } -} \ No newline at end of file +*/ \ No newline at end of file