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: MenuExample exosite_http_example exosite_http_example FastPWM
RGBLed.h
00001 /* 00002 Copyright (c) 2014 Romain Berrada 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00005 and associated documentation files (the "Software"), to deal in the Software without restriction, 00006 including without limitation the rights to use, copy, modify, merge, publish, distribute, 00007 sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00008 furnished to do so, subject to the following conditions: 00009 00010 The above copyright notice and this permission notice shall be included in all copies or 00011 substantial portions of the Software. 00012 00013 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00014 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00015 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00016 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00017 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00018 */ 00019 00020 #ifndef INCLUDE_RGBLED_H 00021 #define INCLUDE_RGBLED_H 00022 00023 #include "mbed.h" 00024 00025 /** A light RGB LED Class \n 00026 Warning : This library is for non-PWN LED \n 00027 Here is an quick hello-world class that makes the LED blink with all colors. \n 00028 @code 00029 #include "mbed.h" 00030 #include "RGBLed.h" 00031 00032 RGBLed led(LED_RED, LED_GREEN, LED_BLUE); 00033 00034 int main() { 00035 RGBLed::Color list[8] = {RGBLed::BLACK, RGBLed::RED, RGBLed::GREEN, RGBLed::BLUE, RGBLed::MAGENTA, RGBLed::CYAN, RGBLed::YELLOW, RGBLed::WHITE}; 00036 int i = 0; 00037 00038 while (true) { 00039 i = (i+1)%8; 00040 led.setColor(list[i]); 00041 wait_ms(100); 00042 } 00043 } 00044 @endcode 00045 */ 00046 class RGBLed { 00047 private: 00048 DigitalOut _red; 00049 DigitalOut _green; 00050 DigitalOut _blue; 00051 00052 public: 00053 /** RGB Color class \n 00054 Colors have been defined and are ready to use in RGBLed class 00055 */ 00056 class Color { 00057 private: 00058 bool _r; /**< Red component of the Color */ 00059 bool _g; /**< Green component of the Color */ 00060 bool _b; /**< Blue component of the Color */ 00061 Color(bool r, bool g, bool b); /**< Constructor */ 00062 friend class RGBLed; 00063 }; 00064 00065 /** Create a RGBLed, containing the informations about the LED pinout. 00066 @param redPin the pin linked to the Red LED 00067 @param greenPin the pin linked to the green LED 00068 @param blue the pin linked to the blue LED 00069 */ 00070 RGBLed(PinName redPin, PinName greenPin, PinName bluePin); 00071 00072 /** Change the color of the LED. 00073 @param color the color to display 00074 @see RGBLed::Color 00075 */ 00076 void setColor(RGBLed::Color& color); 00077 00078 static Color BLACK; /**< Black Color (no color) */ 00079 static Color RED; /**< Red Color */ 00080 static Color GREEN; /**< Green Color */ 00081 static Color BLUE; /**< Blue Color */ 00082 static Color MAGENTA; /**< Magenta Color (Red + Blue) */ 00083 static Color CYAN; /**< Cyan Color (Green + Blue) */ 00084 static Color YELLOW; /**< Yellow Color (Red + Green) */ 00085 static Color WHITE; /**< White Color (Red + Green + Blue) */ 00086 }; 00087 00088 #endif
Generated on Tue Jul 12 2022 14:47:06 by
1.7.2