Markus Reiner
/
MarkusReiner7ABELI
nur mal speichern
Revision 5:2623865343d9, committed 2018-11-29
- Comitter:
- mexx
- Date:
- Thu Nov 29 18:45:12 2018 +0000
- Parent:
- 4:d3a068487721
- Commit message:
- umgeschrieben ohne class
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d3a068487721 -r 2623865343d9 main.cpp --- a/main.cpp Thu Nov 29 18:07:14 2018 +0000 +++ b/main.cpp Thu Nov 29 18:45:12 2018 +0000 @@ -1,4 +1,4 @@ -#include "mbed.h" +/*#include "mbed.h" BusOut Leds(LED1, LED2, LED3, LED4); //BusOut zweiLeds(LED1, LED2); @@ -9,7 +9,7 @@ //DigitalOut led4(LED4); //DigitalIn btn(P14); Ticker tickerflipper; - +volatile int cout = 0; void timeOut(void); enum Status {ST_LEDOFF=0, ST_LEDEIN=1,ST_Error}; @@ -22,7 +22,7 @@ void LedOFF(){write(0x00);} void LedON(int lVal){write(lVal)}; - void LedON(){write(0x0f);} + void LedON(){write(0x03);} }; @@ -90,12 +90,11 @@ void Stm::Ein() { - LedON(){write(0x0f)}; + LedON(){write(0xff)}; wait(0,1); - LedON(){write(0x00)}; + LedOFF(){write(0x00)}; while(true) { - LedON({write(0x0f)}; - if(sw1.CheckFlag()) { + LedON.IsA;cout < 3()) { state = ST_LEDAUS; return; } @@ -104,13 +103,30 @@ void Stm::LedAus(){ while(true) { - led1 = 1; + LedOFF.IsA(); if(sw1.CheckFlag()) { - state = ST_EIN; + return; } } } + +{ + printf("State: LedAUS"); + while(true) { + Leds = 0; + if(CheckFlag()) + { + state = ST_LEDEIN; + return; + } + } +} +void ST_Error (void) +{ + printf("State: ERROR!!!"); + return; +} void Stm::Error(){ while(1) { @@ -143,3 +159,116 @@ else counter++; return; } +*/ + +#include "mbed.h" + +DigitalIn btn(P14); // Taste + + +BusOut BoardLeds ( LED1 , LED2, LED3, LED4); + +Ticker tickflip; // Led Ticker +volatile int blinkerCounter=0; // Volatile, unterschiedlichen Cores + +enum State {ST_LEDAUS=0, ST_LEDEIN}; +State state; + +bool pressed = false; + +void flipper() // +{ + blinkerCounter++; // Variable um led zum binken + Led4 = !Led4; // umschalten +} + + +void rise(void) +{ + wait_ms(200); // Entprellung + pressed = true; //ob gedrückt +} + +bool CheckFlag() +{ + if (pressed) // ob pressed WAHR ist + { + pressed=false; // Rücksetzen + return true; // Rückgabe + } + return false; +} + + +void ST_LedAus (void) +{ + while(true) + { + Led1 = 0; // Led1 + if(CheckFlag()) + { + state = ST_LEDEIN; + return; + } + } +} + + +void ST_LedEin (void) +{ + + tickflip.attach(&flipper, 0.3); // the address of the function to be attached (flip) and the interval (0,3 seconds) + + while(true) // Dauerschleife + { + if ( blinkCounter == 4) break;// wenn couter 4 ist + } + tickflip.detach(); // deaktivieren + blinkCounter=0; // blinkCounter rücksetzen auf 0 damit es wieder von vorne losgehen kann + + + + + while(true) { + Led1 = 1; + + if(CheckFlag()) + { + state = ST_LEDAUS; + + return; + } + } +} + +void ST_Error (void) +{ + Led1 = !Led1; + return; +} + + +void stateMachine() +{ + switch (state) + { + case ST_LEDAUS: ST_LedAus(); + break; + case ST_LEDEIN: ST_LedEin(); + break; + default: ST_Error(); // sollte nicht auftreten :-) + break; + } +} + + + +int main() +{ + SW1.rise(&rise); //.fall(&fall); + state = ST_LEDAUS; + while(true) + { + stateMachine(); + } +} \ No newline at end of file