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.h@1:1f6bd61833a3, 2015-07-31 (annotated)
- Committer:
- wakestrap
- Date:
- Fri Jul 31 18:15:08 2015 +0000
- Revision:
- 1:1f6bd61833a3
- Parent:
- 0:8aa281e74b4a
First Commit, Basic library functions tested and working.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wakestrap | 0:8aa281e74b4a | 1 | |
wakestrap | 0:8aa281e74b4a | 2 | #include "mbed.h" |
wakestrap | 0:8aa281e74b4a | 3 | |
wakestrap | 0:8aa281e74b4a | 4 | /** Simple class for controlling LEDs |
wakestrap | 0:8aa281e74b4a | 5 | * |
wakestrap | 0:8aa281e74b4a | 6 | * Author: Andrew Edwards |
wakestrap | 0:8aa281e74b4a | 7 | * |
wakestrap | 0:8aa281e74b4a | 8 | * Example of use: |
wakestrap | 0:8aa281e74b4a | 9 | * @code |
wakestrap | 0:8aa281e74b4a | 10 | * #include "mbed.h" |
wakestrap | 0:8aa281e74b4a | 11 | * #include "LEDControl.h" |
wakestrap | 0:8aa281e74b4a | 12 | * |
wakestrap | 0:8aa281e74b4a | 13 | * int main() { |
wakestrap | 1:1f6bd61833a3 | 14 | 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. |
wakestrap | 1:1f6bd61833a3 | 15 | * LEDControl Blue(PC_10, &LEDTime); //There is a blue LED on pin PC_10 and it'll use the LEDTime timer. |
wakestrap | 1:1f6bd61833a3 | 16 | * LEDControl Green(PA_13, &LEDTime); // There is a Green LED on pin PA_13 and it'll use the LEDTime Timer. |
wakestrap | 1:1f6bd61833a3 | 17 | * Green.blink(); //default Blink rate is 10Hz, so green will blink at 10Hz |
wakestrap | 1:1f6bd61833a3 | 18 | * Blue.on(); //Turn on the Blue LED. It'll stay on until off() is called. |
wakestrap | 0:8aa281e74b4a | 19 | * wait(2); |
wakestrap | 1:1f6bd61833a3 | 20 | * Green.off(); // Turn Green off |
wakestrap | 1:1f6bd61833a3 | 21 | * Green.toggle(); // This just toggles the LED from it's current state. If it's off, it'll go on. |
wakestrap | 1:1f6bd61833a3 | 22 | * Blue.blink(); // Blue blinks at 10hz |
wakestrap | 1:1f6bd61833a3 | 23 | * Blue.blink(100); // Blue Blink at 100Hz |
wakestrap | 0:8aa281e74b4a | 24 | * Blue.off(); // LED OFF |
wakestrap | 0:8aa281e74b4a | 25 | * } |
wakestrap | 0:8aa281e74b4a | 26 | */ |
wakestrap | 1:1f6bd61833a3 | 27 | |
wakestrap | 1:1f6bd61833a3 | 28 | |
wakestrap | 0:8aa281e74b4a | 29 | class LEDControl { |
wakestrap | 0:8aa281e74b4a | 30 | private: |
wakestrap | 0:8aa281e74b4a | 31 | Timer *_Time; |
wakestrap | 0:8aa281e74b4a | 32 | DigitalOut _led; |
wakestrap | 0:8aa281e74b4a | 33 | float _nextBlink; |
wakestrap | 0:8aa281e74b4a | 34 | public: |
wakestrap | 0:8aa281e74b4a | 35 | LEDControl(PinName pin, Timer *time); |
wakestrap | 0:8aa281e74b4a | 36 | //void blink(int n, float t = 0.2); |
wakestrap | 0:8aa281e74b4a | 37 | void blink(float rate = 5); |
wakestrap | 0:8aa281e74b4a | 38 | void off(); |
wakestrap | 0:8aa281e74b4a | 39 | void on(); |
wakestrap | 0:8aa281e74b4a | 40 | void toggle(); |
wakestrap | 0:8aa281e74b4a | 41 | }; |