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 Oct 08 21:43:02 2015 +0000
Revision:
2:ed46f45e1d66
Parent:
0:9509f771054b
Child:
4:a7a26506c62f
Child:
5:036a21c44cb7
added effects class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sillevl 0:9509f771054b 1
sillevl 0:9509f771054b 2 #include "mbed.h"
sillevl 2:ed46f45e1d66 3 #include "Color.h"
sillevl 0:9509f771054b 4
sillevl 2:ed46f45e1d66 5 #ifndef RGB_H
sillevl 2:ed46f45e1d66 6 #define RGB_H
sillevl 0:9509f771054b 7
sillevl 0:9509f771054b 8 class RGB{
sillevl 0:9509f771054b 9 public:
sillevl 0:9509f771054b 10
sillevl 2:ed46f45e1d66 11 static const int OFF = 0;
sillevl 2:ed46f45e1d66 12
sillevl 0:9509f771054b 13 RGB(PinName r_pin, PinName g_pin, PinName b_pin);
sillevl 0:9509f771054b 14 // void setIntensity(int intensity); // How are we gonna do this?
sillevl 2:ed46f45e1d66 15 void setColor(Color* color);
sillevl 0:9509f771054b 16 void setColor(int color);
sillevl 2:ed46f45e1d66 17 Color* getColor();
sillevl 0:9509f771054b 18
sillevl 0:9509f771054b 19 // void on(); // do we need this? what value to turn on to?
sillevl 0:9509f771054b 20 void off();
sillevl 0:9509f771054b 21
sillevl 0:9509f771054b 22 protected:
sillevl 0:9509f771054b 23 //void setColor(int r, int g, int b);
sillevl 0:9509f771054b 24
sillevl 0:9509f771054b 25 private:
sillevl 0:9509f771054b 26 PwmOut* r_out;
sillevl 0:9509f771054b 27 PwmOut* g_out;
sillevl 0:9509f771054b 28 PwmOut* b_out;
sillevl 0:9509f771054b 29
sillevl 2:ed46f45e1d66 30 Color* color;
sillevl 2:ed46f45e1d66 31
sillevl 2:ed46f45e1d66 32 void setPwmColor(int value, PwmOut* output);
sillevl 2:ed46f45e1d66 33
sillevl 0:9509f771054b 34 };
sillevl 2:ed46f45e1d66 35
sillevl 2:ed46f45e1d66 36 #endif