simple RGB led library

Dependents:   m3Dpi MQTT-Thermostat-example Final_project_Tran Final_project_Tran ... more

RGB-fun

RGB library used to control RGB leds using PWM modulation to dim and mix the individual colors. The library uses a Color helper class to define the colors. It is possible to define colors in these ways:

  • web color notation: #FF00AA
  • Integer notation: 0 - 255
  • Floating point notation: 0.0 - 1.0

By combining red, green and blue a great amount of colors can be created. This class can accept color objects or colors in hexadecimal notation (web color notation).

Note

Effects and effectsmanager are still experimental and not documented.

RGB class reference

Import library

Public Member Functions

RGB (PinName r_pin, PinName g_pin, PinName b_pin)
Create a new RGB instance.
void setColor ( Color *color)
Set the color by giving an instance of an Color object.
void setColor (int color)
Set the color by giving an integer in hexadecimal notation.
Color * getColor ()
Get the current color of the RGB led.
void off ()
Turn the led off.

Color class reference

Import library

Public Types

enum Colors

Enum with named colors for easy use.

More...

Public Member Functions

Color (int red, int green, int blue)
Create Color instance, giving individual red, green and blue factors as integer values.
Color (float red, float green, float blue)
Create Color instance, giving individual red, green and blue factors as floating point values.
Color (int hexColor)
Create Color instance, giving red, green and blue factors as a single integer value.
int getHex ()
Get the color value as an integer in hexadecimal notation.
int getRed ()
Get the red factor of the color.
int getGreen ()
Get the green factor of the color.
int getBlue ()
Get the blue factor of the color.

Example

Repository: rgb-fun-helloworld

Committer:
sillevl
Date:
Thu Dec 03 07:56:55 2015 +0000
Revision:
7:d10cfeb2f18e
Parent:
6:b5a88296bc50
remove .orig files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sillevl 2:ed46f45e1d66 1
sillevl 2:ed46f45e1d66 2 #ifndef COLOR_H
sillevl 2:ed46f45e1d66 3 #define COLOR_H
sillevl 2:ed46f45e1d66 4
sillevl 4:a7a26506c62f 5
sillevl 5:036a21c44cb7 6 /** Color class.
sillevl 5:036a21c44cb7 7 * Used for easy management of colors. Colors can be set by giving individual values for the
sillevl 5:036a21c44cb7 8 * red, green and blue component, both in integer and floating point notation, or as a single
sillevl 5:036a21c44cb7 9 * integer formatted in hexadecimal format (hex triplet), used in web colors.
sillevl 5:036a21c44cb7 10 */
sillevl 2:ed46f45e1d66 11 class Color{
sillevl 6:b5a88296bc50 12
sillevl 2:ed46f45e1d66 13 int red;
sillevl 2:ed46f45e1d66 14 int green;
sillevl 2:ed46f45e1d66 15 int blue;
sillevl 4:a7a26506c62f 16
sillevl 2:ed46f45e1d66 17 void setColor(int red, int green, int blue);
sillevl 4:a7a26506c62f 18
sillevl 2:ed46f45e1d66 19 public:
sillevl 2:ed46f45e1d66 20
sillevl 5:036a21c44cb7 21 /// Enum with named colors for easy use
sillevl 3:edc6e64bfc65 22 enum Colors {RED = 0xFF0000, GREEN = 0x00FF00, BLUE = 0x0000FF, CYAN = 0x00FFFF, MAGENTA = 0xFF00FF, YELLOW = 0xFFFF00, WHITE = 0xFFFFFF, BLACK = 0x000000};
sillevl 4:a7a26506c62f 23
sillevl 5:036a21c44cb7 24 /** Create Color instance, giving individual red, green and blue factors as integer values
sillevl 5:036a21c44cb7 25 * @param red Amount of red to be in the color. This value can be an integer between 0 (0% red) and 255 (100% red)
sillevl 5:036a21c44cb7 26 * @param green Amount of green to be in the color. This value can be an integer between 0 (0% green) and 255 (100% green)
sillevl 5:036a21c44cb7 27 * @param blue Amount of blue to be in the color. This value can be an integer between 0 (0% blue) and 255 (100% blue)
sillevl 5:036a21c44cb7 28 */
sillevl 2:ed46f45e1d66 29 Color(int red, int green, int blue);
sillevl 5:036a21c44cb7 30
sillevl 5:036a21c44cb7 31 /** Create Color instance, giving individual red, green and blue factors as floating point values
sillevl 5:036a21c44cb7 32 * @param red Amount of red to be in the color. This value can be a float between 0.0 (0% red) and 1.0 (100% red)
sillevl 5:036a21c44cb7 33 * @param green Amount of green to be in the color. This value can be a float between 0.0 (0% green) and 1.0 (100% green)
sillevl 5:036a21c44cb7 34 * @param blue Amount of blue to be in the color. This value can a float between 0.0 (0% blue) and 1.0 (100% blue)
sillevl 5:036a21c44cb7 35 */
sillevl 2:ed46f45e1d66 36 Color(float red, float green, float blue);
sillevl 5:036a21c44cb7 37
sillevl 5:036a21c44cb7 38 /** Create Color instance, giving red, green and blue factors as a single integer value
sillevl 5:036a21c44cb7 39 * @param hexColor Color in hexadecimal notation (hex triplet). 24-bit RGB color as used in web colors.
sillevl 5:036a21c44cb7 40 * @note Each color is made up of 8 bits, 0xRRGGBB
sillevl 5:036a21c44cb7 41 *
sillevl 5:036a21c44cb7 42 * Examples:
sillevl 5:036a21c44cb7 43 * @code
sillevl 5:036a21c44cb7 44 * 0xFF0000 = Red
sillevl 5:036a21c44cb7 45 * 0xFFFFE0 = Light yellow
sillevl 5:036a21c44cb7 46 * 0xFA8072 = Salmon
sillevl 5:036a21c44cb7 47 * @endcode
sillevl 5:036a21c44cb7 48 */
sillevl 2:ed46f45e1d66 49 Color(int hexColor);
sillevl 2:ed46f45e1d66 50
sillevl 5:036a21c44cb7 51 /** Get the color value as an integer in hexadecimal notation
sillevl 5:036a21c44cb7 52 * @return color as integer in hexadecimal notation (between 0x000000 and 0xFFFFFF)
sillevl 5:036a21c44cb7 53 */
sillevl 2:ed46f45e1d66 54 int getHex();
sillevl 4:a7a26506c62f 55
sillevl 5:036a21c44cb7 56 /** Get the red factor of the color
sillevl 5:036a21c44cb7 57 * @return red factor as integer between 0 (0% red) and 255 (100% red)
sillevl 5:036a21c44cb7 58 */
sillevl 2:ed46f45e1d66 59 int getRed();
sillevl 5:036a21c44cb7 60
sillevl 5:036a21c44cb7 61 /** Get the green factor of the color
sillevl 5:036a21c44cb7 62 * @return green factor as integer between 0 (0% green) and 255 (100% green)
sillevl 5:036a21c44cb7 63 */
sillevl 2:ed46f45e1d66 64 int getGreen();
sillevl 5:036a21c44cb7 65
sillevl 5:036a21c44cb7 66 /** Get the blue factor of the color
sillevl 5:036a21c44cb7 67 * @return blue factor as integer between 0 (0% blue) and 255 (100% blue)
sillevl 5:036a21c44cb7 68 */
sillevl 2:ed46f45e1d66 69 int getBlue();
sillevl 2:ed46f45e1d66 70 };
sillevl 2:ed46f45e1d66 71
sillevl 2:ed46f45e1d66 72 #endif