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.cpp
00001 /******************** (C) COPYRIGHT 2016 Delta Electronics, Inc. *************** 00002 * 00003 * File Name : Led.cpp 00004 * Authors : Tsungta Wu - CPBG (tsungta.wu@deltaww.com) 00005 * Version : V.1.0.1 00006 * Date : 2016/Nov/14 00007 * 00008 *******************************************************************************/ 00009 00010 #include "Led.h" 00011 #include "mbed.h" 00012 00013 static uint8_t on_logic; 00014 00015 using namespace mbed; 00016 00017 Led::Led(PinName pin, uint8_t On_Logic) : _led(pin) { 00018 on_logic = On_Logic; 00019 _led = !on_logic;//turn off when init 00020 00021 } 00022 00023 static float Int; 00024 static uint8_t* Toggle; 00025 static uint16_t Num; 00026 static uint16_t toggle_cnt; 00027 00028 /**turn off led instantaneous 00029 * usually not used 00030 */ 00031 00032 void Led::offLed() { 00033 _led = !on_logic; 00034 toggle_cnt = Num; 00035 } 00036 00037 /** Turn on led with given duration. 00038 * @param time - the duration of the tone in seconds 00039 */ 00040 00041 void Led::simpleBlink(float time) { 00042 _led = on_logic; 00043 tnext.attach(this,&Led::offLed, time); // time to off 00044 } 00045 00046 void Led::nextToggle() { 00047 if (++toggle_cnt < Num) { 00048 if (Toggle[toggle_cnt] > 0) 00049 _led = on_logic; 00050 else 00051 _led = !on_logic; 00052 tnext.attach(this,&Led::nextToggle, Int); // time to off 00053 } else offLed(); 00054 } 00055 00056 void Led::toggleLed (uint8_t* toggle_on_off, uint16_t toggle_num, float tonggle_time) { 00057 offLed(); 00058 00059 Int = tonggle_time; 00060 Num = toggle_num; 00061 Toggle = toggle_on_off; 00062 00063 toggle_cnt = 0; 00064 if (on_logic) 00065 _led = Toggle[toggle_cnt]; 00066 else 00067 _led = !Toggle[toggle_cnt]; 00068 tnext.attach(this,&Led::nextToggle, Int); // time to off 00069 } 00070
Generated on Mon Jul 25 2022 05:03:58 by
1.7.2