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.
Revision 1:1f6bd61833a3, committed 2015-07-31
- Comitter:
- wakestrap
- Date:
- Fri Jul 31 18:15:08 2015 +0000
- Parent:
- 0:8aa281e74b4a
- Commit message:
- First Commit, Basic library functions tested and working.
Changed in this revision
LEDControl.cpp | Show annotated file Show diff for this revision Revisions of this file |
LEDControl.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8aa281e74b4a -r 1f6bd61833a3 LEDControl.cpp --- a/LEDControl.cpp Thu Jul 09 13:07:50 2015 +0000 +++ b/LEDControl.cpp Fri Jul 31 18:15:08 2015 +0000 @@ -11,9 +11,15 @@ void LEDControl::blink(float rate) { long _currentTime = _Time->read_ms(); + + if(_nextBlink - _currentTime > 5000) + { + _nextBlink = 0; + } + if(_currentTime - _nextBlink > 0) { - if(_currentTime > 20000000) + if(_currentTime > 30000) { _Time->reset(); _currentTime = 0;
diff -r 8aa281e74b4a -r 1f6bd61833a3 LEDControl.h --- a/LEDControl.h Thu Jul 09 13:07:50 2015 +0000 +++ b/LEDControl.h Fri Jul 31 18:15:08 2015 +0000 @@ -11,14 +11,21 @@ * #include "LEDControl.h" * * int main() { - * LEDControl Blue(PC_10); - * Blue.on(); (default blink rate is 10 Hertz) + Timer LEDTime; // Create a Timer for the LEDs to use that isn't used by anything else. Multiple LED objects can all use the same timer. + * LEDControl Blue(PC_10, &LEDTime); //There is a blue LED on pin PC_10 and it'll use the LEDTime timer. + * LEDControl Green(PA_13, &LEDTime); // There is a Green LED on pin PA_13 and it'll use the LEDTime Timer. + * Green.blink(); //default Blink rate is 10Hz, so green will blink at 10Hz + * Blue.on(); //Turn on the Blue LED. It'll stay on until off() is called. * wait(2); - * Blue.on(100); // Blink at 100Hz + * Green.off(); // Turn Green off + * Green.toggle(); // This just toggles the LED from it's current state. If it's off, it'll go on. + * Blue.blink(); // Blue blinks at 10hz + * Blue.blink(100); // Blue Blink at 100Hz * Blue.off(); // LED OFF - * Blue.alwayson(); // LED Stays on until off is called * } */ + + class LEDControl { private: Timer *_Time;