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.
LEDUtil.h
00001 #ifndef __LEDUTIL_H__ 00002 #define __LEDUTIL_H__ 00003 00004 /** 00005 * A simple class to handle LED. 00006 * 00007 * Example (tested on BLENano): 00008 * @code 00009 * #include "mbed.h" 00010 * #include "LEDUtil.h" 00011 * 00012 * // LED is connected to P0_19 on BLENano and it lights up when the pin state is high. 00013 * #define LED_PIN_NAME P0_19 00014 * 00015 * void main() { 00016 * LEDUtil led1(P0_19, LEDUtil::HIGH_ON_LOW_OFF); 00017 * 00018 * while(true) { 00019 * led1.turnOn(); 00020 * wait(0.5); 00021 * led1.turnOff(); 00022 * wait(0.5); 00023 * } 00024 * } 00025 * @endcode 00026 */ 00027 class LEDUtil 00028 { 00029 00030 public: 00031 00032 /** Polarity of LED's configuration. */ 00033 typedef enum { 00034 /** The target LED lights up when the pin level is high. */ 00035 HIGH_ON_LOW_OFF, 00036 /** The target LED lights up when the pin level is low. */ 00037 LOW_ON_HIGH_OFF 00038 } Polarity; 00039 00040 /** 00041 * Constructor. 00042 * 00043 * @param targetPinName pin name of the target pin which is coneccted with the target LED. 00044 * @param targetPinPolarity pin polarity of the target. The default value is POLARITY_HIGH_ON_LOW_OFF 00045 */ 00046 LEDUtil(PinName targetPinName, Polarity targetPinPolarity = HIGH_ON_LOW_OFF); 00047 00048 /** 00049 * Turns on the LED. 00050 */ 00051 void turnOn(); 00052 00053 /** 00054 * Turns off the LED. 00055 */ 00056 void turnOff(); 00057 00058 /** 00059 * Returns if the LED is on. 00060 * @return Returns true if the LED is on. Otherwise returns false. 00061 */ 00062 bool isOn(); 00063 00064 /** 00065 * Returns if the LED is off. 00066 * @return Returns true if the LED is off. Otherwise returns false. 00067 */ 00068 bool isOff(); 00069 00070 /** 00071 * Get polarity setting. 00072 * @return polarity setting of this LED configuration. 00073 */ 00074 Polarity getPolarity(); 00075 00076 00077 private: 00078 00079 /* Holds the target LED's pin name. */ 00080 PinName pinName; 00081 00082 /* Holds polarity of the target LED pin. */ 00083 Polarity polarity; 00084 00085 /* State of the LED, i.e. on or off. */ 00086 typedef enum {LED_ON, LED_OFF} LedState; 00087 00088 /* 00089 * Sets the LED state. 00090 * @param state LED state to be set. 00091 */ 00092 void setLedState(LedState state); 00093 00094 /* 00095 * Gets the LED state. 00096 * @return Returns LED state. 00097 */ 00098 LedState getLedState(); 00099 }; 00100 00101 #endif
Generated on Sat Jul 16 2022 11:12:23 by
1.7.2