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 0:9509f771054b 1
sillevl 0:9509f771054b 2 #include "RGB.h"
sillevl 0:9509f771054b 3
sillevl 4:a7a26506c62f 4 RGB::RGB(PinName r_pin, PinName g_pin, PinName b_pin)
sillevl 4:a7a26506c62f 5 {
sillevl 0:9509f771054b 6 r_out = new PwmOut(r_pin);
sillevl 0:9509f771054b 7 g_out = new PwmOut(g_pin);
sillevl 0:9509f771054b 8 b_out = new PwmOut(b_pin);
sillevl 0:9509f771054b 9 off();
sillevl 0:9509f771054b 10 }
sillevl 0:9509f771054b 11
sillevl 4:a7a26506c62f 12 RGB::~RGB()
sillevl 4:a7a26506c62f 13 {
sillevl 4:a7a26506c62f 14 delete r_out;
sillevl 4:a7a26506c62f 15 delete g_out;
sillevl 4:a7a26506c62f 16 delete b_out;
sillevl 4:a7a26506c62f 17 }
sillevl 4:a7a26506c62f 18
sillevl 4:a7a26506c62f 19 void RGB::setColor(Color* color)
sillevl 4:a7a26506c62f 20 {
sillevl 2:ed46f45e1d66 21 this->color = color;
sillevl 2:ed46f45e1d66 22 setPwmColor(color->getRed(), r_out);
sillevl 2:ed46f45e1d66 23 setPwmColor(color->getGreen(), g_out);
sillevl 2:ed46f45e1d66 24 setPwmColor(color->getBlue(), b_out);
sillevl 0:9509f771054b 25 }
sillevl 0:9509f771054b 26
sillevl 4:a7a26506c62f 27 void RGB::setColor(int color)
sillevl 4:a7a26506c62f 28 {
sillevl 4:a7a26506c62f 29 Color* c = new Color(color);
sillevl 4:a7a26506c62f 30 setColor(c);
sillevl 4:a7a26506c62f 31 delete c;
sillevl 2:ed46f45e1d66 32 }
sillevl 2:ed46f45e1d66 33
sillevl 4:a7a26506c62f 34 Color* RGB::getColor()
sillevl 4:a7a26506c62f 35 {
sillevl 2:ed46f45e1d66 36 return color;
sillevl 0:9509f771054b 37 }
sillevl 0:9509f771054b 38
sillevl 4:a7a26506c62f 39 void RGB::off()
sillevl 4:a7a26506c62f 40 {
sillevl 4:a7a26506c62f 41 Color* color = new Color(0);
sillevl 4:a7a26506c62f 42 setColor(color);
sillevl 4:a7a26506c62f 43 delete color;
sillevl 0:9509f771054b 44 }
sillevl 0:9509f771054b 45
sillevl 4:a7a26506c62f 46 void RGB::setPwmColor(int value, PwmOut* output)
sillevl 4:a7a26506c62f 47 {
sillevl 2:ed46f45e1d66 48 output->write(((~value) & 0xFF) / 255.0f);
sillevl 2:ed46f45e1d66 49 }
sillevl 2:ed46f45e1d66 50