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.
MultipinRGB.h
00001 /****************************************************************************** 00002 * MIT License 00003 * 00004 * Copyright (c) 2017 Justin J. Jordan 00005 * 00006 * Permission is hereby granted, free of charge, to any person obtaining a copy 00007 * of this software and associated documentation files (the "Software"), to deal 00008 * in the Software without restriction, including without limitation the rights 00009 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00010 * copies of the Software, and to permit persons to whom the Software is 00011 * furnished to do so, subject to the following conditions: 00012 00013 * The above copyright notice and this permission notice shall be included in all 00014 * copies or substantial portions of the Software. 00015 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00019 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00022 * SOFTWARE. 00023 ******************************************************************************/ 00024 00025 00026 #ifndef _MULTIPINRGB_H_ 00027 #define _MULTIPINRGB_H_ 00028 00029 #include "mbed.h" 00030 00031 00032 /** 00033 * @brief MutlipinRGB Library 00034 * 00035 * @details Library for multi-pin RGB leds that encapsulates three PwmOut objects 00036 * and provides access to the floating point read/write mbr fxs of the PwmOut 00037 * objects.\n\n 00038 * Duty cycles should always be written as 0.0F for off, and 1.0F as 100% on, 00039 * regardless of led active state.\n\n 00040 * Duty cycles are reported in the same manner.\n\n 00041 * 00042 * @code 00043 * #include "mbed.h" 00044 * #include "MultipinRGB.h" 00045 * 00046 * int main () 00047 * { 00048 * MultipinRGB leds(LED1, LED2, LED3); 00049 * float redDutyCycle(0.5F), grnDutyCycle(0.0F), bluDutyCycle(0.0F), temp; 00050 * 00051 * while(1) 00052 * { 00053 * leds.writeLeds(redDutyCycle, grnDutyCycle, bluDutyCycle); 00054 * 00055 * printf("RGB Duty Cycles = %3.1f, %3.1f, %3.1f\r\n", 00056 * redDutyCycle, grnDutyCycle, bluDutyCycle); 00057 * 00058 * //shift r->g->b->r 00059 * temp = bluDutyCycle; 00060 * bluDutyCycle = grnDutyCycle; 00061 * grnDutyCycle = redDutyCycle; 00062 * redDutyCycle = temp; 00063 * 00064 * wait(0.25); 00065 * } 00066 * } 00067 * @endcode 00068 * 00069 */ 00070 class MultipinRGB 00071 { 00072 public: 00073 00074 enum Led_e 00075 { 00076 Red, 00077 Green, 00078 Blue 00079 }; 00080 00081 enum LedLogic_e 00082 { 00083 ActiveLow, 00084 ActiveHigh 00085 }; 00086 00087 ///Constructor 00088 ///@param[in] red - Pin that red led is connected to. 00089 ///@param[in] green - Pin that green led is connected to. 00090 ///@param[in] blue - Pin that blue led is connected to. 00091 ///@param[in] activeState - Active state of all three leds. 00092 MultipinRGB(PinName red, PinName green, PinName blue, LedLogic_e 00093 activeState = ActiveLow); 00094 00095 ///Destructor 00096 ~MultipinRGB(); 00097 00098 ///@brief Sets duty cycle for led.\n 00099 /// 00100 ///On Entry: 00101 ///@param[in] led - Led to update 00102 ///@param[in] dc - Duty cycle for led, 0.0 to 1.0 00103 /// 00104 ///On Exit: 00105 ///@param[out] none 00106 /// 00107 ///@returns none 00108 void writeLed(const Led_e led, const float dc); 00109 00110 ///@brief Sets duty cycle for all three leds.\n 00111 /// 00112 ///On Entry: 00113 ///@param[in] r - Duty cycle for led, 0.0 to 1.0 00114 ///@param[in] g - Duty cycle for led, 0.0 to 1.0 00115 ///@param[in] b - Duty cycle for led, 0.0 to 1.0 00116 /// 00117 ///On Exit: 00118 ///@param[out] none 00119 /// 00120 ///@returns none 00121 void writeLeds(const float r, const float g, const float b); 00122 00123 ///@brief Reads duty cycle for led.\n 00124 /// 00125 ///On Entry: 00126 ///@param[in] led - Led to update 00127 /// 00128 ///On Exit: 00129 ///@param[out] none 00130 /// 00131 ///@returns Current duty cycle for led, 0.0 to 1.0 00132 float readLed(const Led_e led); 00133 00134 ///@brief Reads duty cycle for all three leds.\n 00135 /// 00136 ///On Entry: 00137 ///@param[in] r - float reference for red led duty cycle. 00138 ///@param[in] g - float reference for green led duty cycle. 00139 ///@param[in] b - float reference for blue led duty cycle. 00140 /// 00141 ///On Exit: 00142 ///@param[out] r - Current duty cycle for led, 0.0 to 1.0 00143 ///@param[out] g - Current duty cycle for led, 0.0 to 1.0 00144 ///@param[out] b - Current duty cycle for led, 0.0 to 1.0 00145 /// 00146 ///@returns none 00147 void readLeds(float& r, float& g, float& b); 00148 00149 ///@brief Toggles led from off to on, or on to off.\n 00150 ///Duty Cycle will be 0% or 100% after this call.\n 00151 /// 00152 ///On Entry: 00153 ///@param[in] led - Led to toggle 00154 /// 00155 ///On Exit: 00156 ///@param[out] none 00157 /// 00158 ///@returns none 00159 void toggleLed(const Led_e led); 00160 00161 ///@brief Sets pwm period for all three leds.\n 00162 /// 00163 ///On Entry: 00164 ///@param[in] p - PWM period in seconds 00165 /// 00166 ///On Exit: 00167 ///@param[out] none 00168 /// 00169 ///@returns none 00170 void setPeriod(const float p); 00171 00172 private: 00173 00174 PwmOut m_red; 00175 PwmOut m_green; 00176 PwmOut m_blue; 00177 00178 LedLogic_e m_ledActiveState; 00179 }; 00180 00181 00182 ///@brief fx documentation template.\n 00183 /// 00184 ///On Entry: 00185 ///@param[in] none 00186 /// 00187 ///On Exit: 00188 ///@param[out] none 00189 /// 00190 ///@returns none 00191 00192 #endif /*_MULTIPINRGB_H_ */
Generated on Sun Jul 17 2022 02:57:35 by
1.7.2