Library thread Blink Led or other processes use RTOS
Fork of BlinkLed by
Example
https://developer.mbed.org/users/AVELARDEV/code/LedsThreading/
Revision 3:f317d057edde, committed 2016-05-24
- Comitter:
- AVELARDEV
- Date:
- Tue May 24 06:38:16 2016 +0000
- Parent:
- 2:1d0c09c1a8b4
- Child:
- 4:3b34689ec230
- Commit message:
- Reduce BlinkLed library togayan
Changed in this revision
BlinkLed.cpp | Show annotated file Show diff for this revision Revisions of this file |
BlinkLed.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/BlinkLed.cpp Mon Dec 24 06:38:42 2012 +0000 +++ b/BlinkLed.cpp Tue May 24 06:38:16 2016 +0000 @@ -1,10 +1,8 @@ #include "BlinkLed.h" -BlinkLed::BlinkLed(PinName pin, float dutyChangeStep) : +BlinkLed::BlinkLed(PinName pin, int n) : led(pin), - dutyChangeStep(dutyChangeStep), - pause(true), - thread(0) + n(n) { } @@ -14,39 +12,16 @@ void BlinkLed::startBlink() { - pause = false; - if(!thread) - { - thread = new Thread(blink, this, osPriorityNormal, 128, NULL); - } - thread->signal_set(1); -} - -void BlinkLed::finishBlink() -{ - pause = true; -} - -bool BlinkLed::isBlinking() -{ - return !pause; + thread = new Thread(blink, this); } void BlinkLed::blink(void const *argument) { BlinkLed* self = (BlinkLed*)argument; - bool sign = false; while(1) { - if(self->pause) - { - self->led = 0.0F; - Thread::signal_wait(1); - } - float brightness = self->led; - sign = (brightness <= 0.0F) ? true : (1.0F <= brightness) ? false : sign; - self->led = sign ? brightness + self->dutyChangeStep : brightness - self->dutyChangeStep; - Thread::wait(20); + self->led = !self->led; + Thread::wait(self->n); } }
--- a/BlinkLed.h Mon Dec 24 06:38:42 2012 +0000 +++ b/BlinkLed.h Tue May 24 06:38:16 2016 +0000 @@ -12,7 +12,7 @@ public: /** Constructor */ - BlinkLed(PinName pin, float dutyChangeStep); + BlinkLed(PinName, int); /** Destructor */ @@ -21,14 +21,6 @@ /** Start biinking */ void startBlink(); - - /** Finish biinking - */ - void finishBlink(); - - /** Check biinking - */ - bool isBlinking(); private: /** Copy constructor @@ -48,15 +40,11 @@ /** Target Led */ - PwmOut led; + DigitalOut led; - /** Duty ratio step of changing every 20ms + /** Blink time */ - float dutyChangeStep; - - /** Flag of pause - */ - bool pause; + int n; /** Pointer to thread for blinking */