Library thread Blink Led or other processes use RTOS
Fork of BlinkLed by
Example
https://developer.mbed.org/users/AVELARDEV/code/LedsThreading/
Diff: BlinkLed.cpp
- Revision:
- 0:a55a3351317d
- Child:
- 1:54071e781f77
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BlinkLed.cpp Sat Sep 01 04:02:02 2012 +0000 @@ -0,0 +1,48 @@ +#include "BlinkLed.h" + +BlinkLed::BlinkLed(PinName pin, float dutyChangeStep) : +led(pin), +dutyChangeStep(dutyChangeStep), +pause(true), +thread(0) +{ +} + +BlinkLed::~BlinkLed() +{ +} + +void BlinkLed::startBlink() +{ + pause = false; + if(thread == 0) + { + thread = new Thread(blink, this, osPriorityNormal, 128, NULL); + } +} + +void BlinkLed::finishBlink() +{ + pause = true; +} + +void BlinkLed::blink(void const *argument) +{ + BlinkLed* self = (BlinkLed*)argument; + + bool sign = false; + while (1) + { + if(self->pause) + { + self->led = 0.0F; + } + else + { + 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); + } +}