Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: non_blocking_Led_Buzze_HelloWorld
Led.h@0:c18c119011ec, 2016-11-21 (annotated)
- Committer:
 - tsungta
 - Date:
 - Mon Nov 21 06:40:27 2016 +0000
 - Revision:
 - 0:c18c119011ec
 
Library for non blocking Led and Buzzer controller
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| tsungta | 0:c18c119011ec | 1 | /******************** (C) COPYRIGHT 2016 Delta Electronics, Inc. *************** | 
| tsungta | 0:c18c119011ec | 2 | * | 
| tsungta | 0:c18c119011ec | 3 | * File Name : Led.h | 
| tsungta | 0:c18c119011ec | 4 | * Authors : Tsungta Wu - CPBG (tsungta.wu@deltaww.com) | 
| tsungta | 0:c18c119011ec | 5 | * Version : V.1.0.1 | 
| tsungta | 0:c18c119011ec | 6 | * Date : 2016/Nov/14 | 
| tsungta | 0:c18c119011ec | 7 | * | 
| tsungta | 0:c18c119011ec | 8 | *******************************************************************************/ | 
| tsungta | 0:c18c119011ec | 9 | |
| tsungta | 0:c18c119011ec | 10 | /** class to make control LED on/off fashion using GPIO | 
| tsungta | 0:c18c119011ec | 11 | * The class use a timer to change led on/off - it is not blocking while scheduling led on/off | 
| tsungta | 0:c18c119011ec | 12 | * | 
| tsungta | 0:c18c119011ec | 13 | * Example: | 
| tsungta | 0:c18c119011ec | 14 | * @code | 
| tsungta | 0:c18c119011ec | 15 | * #include "mbed.h" | 
| tsungta | 0:c18c119011ec | 16 | * #include "Led.h" | 
| tsungta | 0:c18c119011ec | 17 | * | 
| tsungta | 0:c18c119011ec | 18 | * Led led(LED1); | 
| tsungta | 0:c18c119011ec | 19 | * | 
| tsungta | 0:c18c119011ec | 20 | *#define schedule_num 7 | 
| tsungta | 0:c18c119011ec | 21 | *float toggle[schedule_num] = {1, 1, 1, 0, 1, 0, 1}; | 
| tsungta | 0:c18c119011ec | 22 | |
| tsungta | 0:c18c119011ec | 23 | * int main() { | 
| tsungta | 0:c18c119011ec | 24 | * ... | 
| tsungta | 0:c18c119011ec | 25 | * led.simpleBlink(0.5); //turn on led for 0.5 second | 
| tsungta | 0:c18c119011ec | 26 | * ... | 
| tsungta | 0:c18c119011ec | 27 | * led.toggleLed(toggle, schedule_num, 0.5); //change led to on or off every 0.5 second | 
| tsungta | 0:c18c119011ec | 28 | * ... | 
| tsungta | 0:c18c119011ec | 29 | * } | 
| tsungta | 0:c18c119011ec | 30 | * @endcode | 
| tsungta | 0:c18c119011ec | 31 | */ | 
| tsungta | 0:c18c119011ec | 32 | |
| tsungta | 0:c18c119011ec | 33 | #ifndef MBED_LED_H | 
| tsungta | 0:c18c119011ec | 34 | #define MBED_LED_H | 
| tsungta | 0:c18c119011ec | 35 | |
| tsungta | 0:c18c119011ec | 36 | #include "mbed.h" | 
| tsungta | 0:c18c119011ec | 37 | |
| tsungta | 0:c18c119011ec | 38 | namespace mbed { | 
| tsungta | 0:c18c119011ec | 39 | |
| tsungta | 0:c18c119011ec | 40 | |
| tsungta | 0:c18c119011ec | 41 | /* Class: Led | 
| tsungta | 0:c18c119011ec | 42 | * A class witch uses DigitalOut to on/off LED. | 
| tsungta | 0:c18c119011ec | 43 | * The class use a timer to toggle - it is not blocking | 
| tsungta | 0:c18c119011ec | 44 | */ | 
| tsungta | 0:c18c119011ec | 45 | class Led { | 
| tsungta | 0:c18c119011ec | 46 | |
| tsungta | 0:c18c119011ec | 47 | public: | 
| tsungta | 0:c18c119011ec | 48 | |
| tsungta | 0:c18c119011ec | 49 | Led (PinName pin, uint8_t On_Logic = 0); | 
| tsungta | 0:c18c119011ec | 50 | |
| tsungta | 0:c18c119011ec | 51 | /** Turn on LED with given duration. | 
| tsungta | 0:c18c119011ec | 52 | * | 
| tsungta | 0:c18c119011ec | 53 | * @param time - the LED on duration in seconds | 
| tsungta | 0:c18c119011ec | 54 | */ | 
| tsungta | 0:c18c119011ec | 55 | void simpleBlink (float time); | 
| tsungta | 0:c18c119011ec | 56 | |
| tsungta | 0:c18c119011ec | 57 | /** Toggle LED with given sequence and duration. | 
| tsungta | 0:c18c119011ec | 58 | * | 
| tsungta | 0:c18c119011ec | 59 | * @param toggle_on_off - the on/off controlling sequence | 
| tsungta | 0:c18c119011ec | 60 | * @param toggle_num - the total number of the on/off operation | 
| tsungta | 0:c18c119011ec | 61 | * @param tonggle_time - the duration of each on/off operation in seconds | 
| tsungta | 0:c18c119011ec | 62 | */ | 
| tsungta | 0:c18c119011ec | 63 | void toggleLed (uint8_t* toggle_on_off, uint16_t toggle_num, float tonggle_time); | 
| tsungta | 0:c18c119011ec | 64 | |
| tsungta | 0:c18c119011ec | 65 | /** turn off the Led instantaneous | 
| tsungta | 0:c18c119011ec | 66 | * usually not used | 
| tsungta | 0:c18c119011ec | 67 | */ | 
| tsungta | 0:c18c119011ec | 68 | void offLed(); | 
| tsungta | 0:c18c119011ec | 69 | |
| tsungta | 0:c18c119011ec | 70 | private : | 
| tsungta | 0:c18c119011ec | 71 | |
| tsungta | 0:c18c119011ec | 72 | void nextToggle(); | 
| tsungta | 0:c18c119011ec | 73 | DigitalOut _led; | 
| tsungta | 0:c18c119011ec | 74 | Timeout tnext; | 
| tsungta | 0:c18c119011ec | 75 | PinName _debug; | 
| tsungta | 0:c18c119011ec | 76 | }; | 
| tsungta | 0:c18c119011ec | 77 | |
| tsungta | 0:c18c119011ec | 78 | } | 
| tsungta | 0:c18c119011ec | 79 | #endif | 
| tsungta | 0:c18c119011ec | 80 |