Delta / non_blocking_Led_Buzzer

Dependents:   non_blocking_Led_Buzze_HelloWorld

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Led.h Source File

Led.h

00001 /******************** (C) COPYRIGHT 2016 Delta Electronics, Inc. ***************
00002 *
00003 * File Name : Led.h
00004 * Authors   : Tsungta Wu - CPBG (tsungta.wu@deltaww.com)
00005 * Version   : V.1.0.1
00006 * Date      : 2016/Nov/14
00007 *
00008 *******************************************************************************/
00009 
00010 /** class to make control LED on/off fashion using GPIO
00011  *   The class use a timer to change led on/off  - it is not blocking while scheduling led on/off
00012  *
00013  * Example:
00014  * @code
00015  * #include "mbed.h"
00016  * #include "Led.h"
00017  * 
00018  * Led led(LED1);
00019  * 
00020  *#define schedule_num   7
00021  *float toggle[schedule_num] = {1, 1, 1, 0, 1, 0, 1};
00022 
00023  * int main() {
00024  *       ...
00025  *   led.simpleBlink(0.5);   //turn on led for 0.5 second    
00026  *       ...
00027  *   led.toggleLed(toggle, schedule_num, 0.5);    //change led to on or off every 0.5 second
00028  *       ...
00029  * }
00030  * @endcode
00031  */
00032  
00033 #ifndef MBED_LED_H
00034 #define MBED_LED_H
00035 
00036 #include "mbed.h"
00037 
00038 namespace mbed {
00039 
00040 
00041 /* Class: Led
00042  *  A class witch uses DigitalOut to on/off LED.
00043  *  The class use a timer to toggle  - it is not blocking
00044  */
00045 class Led {
00046 
00047 public:
00048 
00049     Led (PinName pin, uint8_t On_Logic = 0);
00050     
00051 /** Turn on LED with given duration.
00052  *
00053  * @param time - the LED on duration in seconds
00054  */
00055     void simpleBlink (float time);
00056 
00057 /** Toggle LED with given sequence and duration.
00058  *
00059  * @param toggle_on_off - the on/off controlling sequence 
00060  * @param toggle_num - the total number of the on/off operation
00061  * @param tonggle_time - the duration of each on/off operation in seconds
00062  */
00063     void toggleLed (uint8_t* toggle_on_off, uint16_t toggle_num, float tonggle_time);
00064     
00065 /** turn off the Led instantaneous 
00066  * usually not used 
00067  */
00068     void offLed();
00069  
00070 private :
00071     
00072     void nextToggle();
00073     DigitalOut _led;
00074     Timeout tnext;
00075     PinName _debug;    
00076 };
00077 
00078 }
00079 #endif
00080