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@0:8aa281e74b4a, 2015-07-09 (annotated)
- Committer:
- wakestrap
- Date:
- Thu Jul 09 13:07:50 2015 +0000
- Revision:
- 0:8aa281e74b4a
- Child:
- 1:1f6bd61833a3
Pre-Cleanup
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 | 0:8aa281e74b4a | 14 | * LEDControl Blue(PC_10); |
wakestrap | 0:8aa281e74b4a | 15 | * Blue.on(); (default blink rate is 10 Hertz) |
wakestrap | 0:8aa281e74b4a | 16 | * wait(2); |
wakestrap | 0:8aa281e74b4a | 17 | * Blue.on(100); // Blink at 100Hz |
wakestrap | 0:8aa281e74b4a | 18 | * Blue.off(); // LED OFF |
wakestrap | 0:8aa281e74b4a | 19 | * Blue.alwayson(); // LED Stays on until off is called |
wakestrap | 0:8aa281e74b4a | 20 | * } |
wakestrap | 0:8aa281e74b4a | 21 | */ |
wakestrap | 0:8aa281e74b4a | 22 | class LEDControl { |
wakestrap | 0:8aa281e74b4a | 23 | private: |
wakestrap | 0:8aa281e74b4a | 24 | Timer *_Time; |
wakestrap | 0:8aa281e74b4a | 25 | DigitalOut _led; |
wakestrap | 0:8aa281e74b4a | 26 | float _nextBlink; |
wakestrap | 0:8aa281e74b4a | 27 | public: |
wakestrap | 0:8aa281e74b4a | 28 | LEDControl(PinName pin, Timer *time); |
wakestrap | 0:8aa281e74b4a | 29 | //void blink(int n, float t = 0.2); |
wakestrap | 0:8aa281e74b4a | 30 | void blink(float rate = 5); |
wakestrap | 0:8aa281e74b4a | 31 | void off(); |
wakestrap | 0:8aa281e74b4a | 32 | void on(); |
wakestrap | 0:8aa281e74b4a | 33 | void toggle(); |
wakestrap | 0:8aa281e74b4a | 34 | }; |