Simple library for controlling LEDs. Turn them on & off, blink them at specified rates and toggle their output. Don't forget to add a timer for the LEDs to use. Documentation found in header file.
LEDControl.cpp
- Committer:
- wakestrap
- Date:
- 2015-07-31
- Revision:
- 1:1f6bd61833a3
- Parent:
- 0:8aa281e74b4a
File content as of revision 1:1f6bd61833a3:
#include "LEDControl.h"
#include "mbed.h"
LEDControl::LEDControl(PinName pin, Timer *time):
_led(pin),
_nextBlink( 0 ),
_Time ( time )
{
_led = 0;
}
void LEDControl::blink(float rate) {
long _currentTime = _Time->read_ms();
if(_nextBlink - _currentTime > 5000)
{
_nextBlink = 0;
}
if(_currentTime - _nextBlink > 0)
{
if(_currentTime > 30000)
{
_Time->reset();
_currentTime = 0;
}
_led = !_led;
_nextBlink = 1000/rate + _currentTime;
}
}
void LEDControl::off() {
_led = 0;
}
void LEDControl::on() {
_led = 1;
}
void LEDControl::toggle() {
_led = !_led;
}