Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BlinkLed HTTPClient EthernetInterface FatFileSystemCpp MSCFileSystem mbed-rtos mbed
BlinkLed.cpp
- Committer:
- togayan
- Date:
- 2012-08-28
- Revision:
- 5:66c3398a14c9
- Parent:
- 0:dfd5cfea7112
File content as of revision 5:66c3398a14c9:
#include "BlinkLed.h"
BlinkLed::BlinkLed(PinName pin, float dutyChangeStep, const char* name) :
led(pin, name),
dutyChangeStep(dutyChangeStep),
continueBlink(false),
thread(0)
{
}
BlinkLed::~BlinkLed()
{
}
void BlinkLed::startBlink()
{
if(continueBlink == false)
{
continueBlink = true;
thread = new Thread(blink, this, osPriorityNormal, 128, NULL);
}
}
void BlinkLed::finishBlink()
{
if(continueBlink == true)
{
continueBlink = false;
led = 0.0;
thread->terminate();
delete thread;
}
}
void BlinkLed::blink(void const *argument)
{
BlinkLed* blinkLed = (BlinkLed*)argument;
bool up = false;
float brightness = 0.0;
while (blinkLed->continueBlink == true)
{
if(brightness <= 0.0)
{
up = true;
}
else if(1.0 <= brightness)
{
up = false;
}
float dutyChangeStep = blinkLed->dutyChangeStep;
brightness += ((up)?(dutyChangeStep):(-dutyChangeStep));
blinkLed->led = brightness;
Thread::wait(20);
}
}