Stm for the project "Fahradlicht"
Revision 0:3d7042171419, committed 2018-11-23
- Comitter:
- lordofthestorm12
- Date:
- Fri Nov 23 15:26:49 2018 +0000
- Commit message:
- stm class;
Changed in this revision
STM_Fahrrad_Licht.cpp | Show annotated file Show diff for this revision Revisions of this file |
STM_Fahrrad_Licht.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 3d7042171419 STM_Fahrrad_Licht.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/STM_Fahrrad_Licht.cpp Fri Nov 23 15:26:49 2018 +0000 @@ -0,0 +1,125 @@ +#include "STM_Fahrrad_Licht.h" + +StateDefine::StateDefine() +{ + _stmTimer.start(); + _curLEDPos = 1; + _timerval = 0.1; +} + +void StateDefine::st_off(void) +{ + _STMLed.setLED(0); +} + +void StateDefine::st_all(void) +{ + _STMLed.setLED(7); +} + +void StateDefine:: st_ll() +{ + if(_stmTimer >= _timerval || _stmTimer <= 0) { + + _curLEDPos--; + + if(_curLEDPos >= 1 && _curLEDPos <= 4) { + ; + _stmTimer.reset(); + _STMLed.setLED(_curLEDPos); + } else { + _stmTimer.reset(); + _curLEDPos = 4; + _STMLed.setLED(_curLEDPos); + } + + } +} + +void StateDefine:: st_lr() +{ + if(_stmTimer >= _timerval || _stmTimer <= 0) { + + _curLEDPos++; + + if(_curLEDPos >= 1 && _curLEDPos <= 4) { + ; + _stmTimer.reset(); + _STMLed.setLED(_curLEDPos); + } else { + _stmTimer.reset(); + _curLEDPos = 1; + _STMLed.setLED(_curLEDPos); + } + + } +} + +void StateDefine:: st_blinki() +{ + + if(_stmTimer >= 0.5 || _stmTimer <= 0) { + + if(_curLEDPos == 1) { + _curLEDPos++; + _STMLed.setLED(7); + _stmTimer.reset(); + } else { + _curLEDPos = 1; + _STMLed.setLED(0); + _stmTimer.reset(); + } + } +} + +void StateDefine:: st_defblinki() +{ + + if(_stmTimer >= _timerval || _stmTimer <= 0) { + + if(_curLEDPos == 1) { + _curLEDPos++; + _STMLed.setLED(7); + _stmTimer.reset(); + } else { + _curLEDPos = 1; + _STMLed.setLED(0); + _stmTimer.reset(); + } + } +} + +void StateDefine:: st_policelight() +{ + + if(_stmTimer >= 0.25 || _stmTimer <= 0) { + + if(_curLEDPos == 1) { + _curLEDPos++; + _STMLed.setLED(5); + _stmTimer.reset(); + } else { + _curLEDPos = 1; + _STMLed.setLED(6); + _stmTimer.reset(); + } + } + +} + +void StateDefine:: STATEChange(CurState aCS , float aCurTimerVal){ + + _timerval = aCurTimerVal; + + switch(aCS){ + case OFF: st_off(); break; + case ALL: st_all(); break; + case LL: st_ll(); break; + case LR: st_lr(); break; + case BLINKI: st_blinki(); break; + case DEFBLINKI: st_defblinki(); break; + case POLICELIGHT: st_policelight();break; + } + + + }
diff -r 000000000000 -r 3d7042171419 STM_Fahrrad_Licht.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/STM_Fahrrad_Licht.h Fri Nov 23 15:26:49 2018 +0000 @@ -0,0 +1,35 @@ +#ifndef STM_FAHRRAD_LICHT_H +#define STM_FAHRRAD_LICHT_H + +#include "mbed.h" +#include "Led_Func_Lib.h" + +enum CurState{OFF, ALL, LL, LR, BLINKI, DEFBLINKI,POLICELIGHT}; + +class StateDefine : Led_Func{ + + public: + StateDefine(); + void st_off(); + void st_all(); + void st_ll(); + void st_lr(); + void st_blinki(); + void st_defblinki(); + void st_policelight(); + + void STATEChange(CurState aCS, float aCurTimerVal); + + private: + + Led_Func _STMLed; + + protected: + + Timer _stmTimer; + int _curLEDPos; + float _timerval; + + }; + +#endif \ No newline at end of file