Andrew Wakestrap / LEDControl
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LEDControl.h Source File

LEDControl.h

00001 
00002 #include "mbed.h"
00003 
00004 /** Simple class for controlling LEDs 
00005  * 
00006  * Author: Andrew Edwards
00007  *
00008  * Example of use:
00009  * @code
00010  * #include "mbed.h"
00011  * #include "LEDControl.h"
00012  *
00013  * int main() {
00014      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.
00015  *    LEDControl Blue(PC_10, &LEDTime); //There is a blue LED on pin PC_10 and it'll use the LEDTime timer.
00016  *    LEDControl Green(PA_13, &LEDTime); // There is a Green LED on pin PA_13 and it'll use the LEDTime Timer.
00017  *    Green.blink(); //default Blink rate is 10Hz, so green will blink at 10Hz
00018  *    Blue.on(); //Turn on the Blue LED. It'll stay on until off() is called.
00019  *    wait(2);
00020  *    Green.off(); // Turn Green off
00021  *    Green.toggle(); // This just toggles the LED from it's current state. If it's off, it'll go on. 
00022  *    Blue.blink(); // Blue blinks at 10hz
00023  *    Blue.blink(100); // Blue Blink at 100Hz
00024  *    Blue.off(); // LED OFF
00025  * }
00026  */
00027  
00028  
00029 class LEDControl {
00030 private:
00031     Timer *_Time;
00032     DigitalOut _led;
00033     float _nextBlink;
00034 public:
00035     LEDControl(PinName pin, Timer *time);
00036     //void blink(int n, float t = 0.2);
00037     void blink(float rate = 5);
00038     void off();
00039     void on();
00040     void toggle();
00041 };