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:
4:a7a26506c62f
remove .orig files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sillevl 2:ed46f45e1d66 1
sillevl 2:ed46f45e1d66 2 #include "Color.h"
sillevl 2:ed46f45e1d66 3
sillevl 2:ed46f45e1d66 4
sillevl 4:a7a26506c62f 5 Color::Color(int red, int green, int blue)
sillevl 4:a7a26506c62f 6 {
sillevl 2:ed46f45e1d66 7 setColor(red, green, blue);
sillevl 2:ed46f45e1d66 8 }
sillevl 2:ed46f45e1d66 9
sillevl 4:a7a26506c62f 10 Color::Color(float red, float green, float blue)
sillevl 4:a7a26506c62f 11 {
sillevl 2:ed46f45e1d66 12 setColor((int) red * 255.0f, (int) green * 255.0f, (int) blue * 255.0f);
sillevl 2:ed46f45e1d66 13 }
sillevl 2:ed46f45e1d66 14
sillevl 4:a7a26506c62f 15 Color::Color(int color)
sillevl 4:a7a26506c62f 16 {
sillevl 2:ed46f45e1d66 17 setColor((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);
sillevl 2:ed46f45e1d66 18 }
sillevl 4:a7a26506c62f 19
sillevl 4:a7a26506c62f 20 int Color::getHex()
sillevl 4:a7a26506c62f 21 {
sillevl 2:ed46f45e1d66 22 return ((red << 16) || (green << 8) || (blue << 0));
sillevl 2:ed46f45e1d66 23 }
sillevl 2:ed46f45e1d66 24
sillevl 4:a7a26506c62f 25 int Color::getRed()
sillevl 4:a7a26506c62f 26 {
sillevl 2:ed46f45e1d66 27 return red;
sillevl 2:ed46f45e1d66 28 }
sillevl 2:ed46f45e1d66 29
sillevl 4:a7a26506c62f 30 int Color::getGreen()
sillevl 4:a7a26506c62f 31 {
sillevl 2:ed46f45e1d66 32 return green;
sillevl 2:ed46f45e1d66 33 }
sillevl 2:ed46f45e1d66 34
sillevl 4:a7a26506c62f 35 int Color::getBlue()
sillevl 4:a7a26506c62f 36 {
sillevl 2:ed46f45e1d66 37 return blue;
sillevl 2:ed46f45e1d66 38 }
sillevl 2:ed46f45e1d66 39
sillevl 4:a7a26506c62f 40 void Color::setColor(int red, int green, int blue)
sillevl 4:a7a26506c62f 41 {
sillevl 2:ed46f45e1d66 42 this->red = red;
sillevl 2:ed46f45e1d66 43 this->green = green;
sillevl 4:a7a26506c62f 44 this->blue = blue;
sillevl 2:ed46f45e1d66 45 }