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 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 4:a7a26506c62f 8
sillevl 5:036a21c44cb7 9 /** RGB class
sillevl 5:036a21c44cb7 10 * Used to control RGB leds using PWM modulation to dim the individual colors. By combining red, green and blue
sillevl 6:b5a88296bc50 11 * a great amount of colors can be created. This class can accept color objects or colors in hexadecimal notation (web color notation)
sillevl 6:b5a88296bc50 12 * Example usage:
sillevl 6:b5a88296bc50 13 * @code
sillevl 6:b5a88296bc50 14 *
sillevl 6:b5a88296bc50 15 * #include "mbed.h"
sillevl 6:b5a88296bc50 16 * #include "RGB.h"
sillevl 6:b5a88296bc50 17 * RGB led(p23,p24,p25);
sillevl 6:b5a88296bc50 18 *
sillevl 6:b5a88296bc50 19 * void main(){
sillevl 6:b5a88296bc50 20 * led.off();
sillevl 6:b5a88296bc50 21 *
sillevl 6:b5a88296bc50 22 * wait(1.0);
sillevl 6:b5a88296bc50 23 *
sillevl 6:b5a88296bc50 24 * // setting the color using the Color enum with named colors
sillevl 6:b5a88296bc50 25 * led.setColor(Color::RED);
sillevl 6:b5a88296bc50 26 *
sillevl 6:b5a88296bc50 27 * // setting the color using a hexadecimal notated integer (yellow)
sillevl 6:b5a88296bc50 28 * led.setColor(0xFFFF00);
sillevl 6:b5a88296bc50 29 *
sillevl 6:b5a88296bc50 30 * // setting the color using an instance of the Color class
sillevl 6:b5a88296bc50 31 * Color* myColor = new Color(0.0,1.0,0.0);
sillevl 6:b5a88296bc50 32 * led.setColor(myColor);
sillevl 6:b5a88296bc50 33 * delete myColor;
sillevl 6:b5a88296bc50 34 * }
sillevl 6:b5a88296bc50 35 * @endcode
sillevl 5:036a21c44cb7 36 */
sillevl 0:9509f771054b 37 class RGB{
sillevl 0:9509f771054b 38 public:
sillevl 0:9509f771054b 39
sillevl 2:ed46f45e1d66 40 static const int OFF = 0;
sillevl 4:a7a26506c62f 41
sillevl 5:036a21c44cb7 42 /** Create a new RGB instance
sillevl 5:036a21c44cb7 43 * @param r_pin mbed PinName that supports PWM output assigned to the red led
sillevl 5:036a21c44cb7 44 * @param g_pin mbed PinName that supports PWM output assigned to the green led
sillevl 5:036a21c44cb7 45 * @param b_pin mbed PinName that supports PWM output assigned to the blue led
sillevl 5:036a21c44cb7 46 */
sillevl 0:9509f771054b 47 RGB(PinName r_pin, PinName g_pin, PinName b_pin);
sillevl 4:a7a26506c62f 48 ~RGB();
sillevl 5:036a21c44cb7 49
sillevl 5:036a21c44cb7 50 /** Set the color by giving an instance of an Color object
sillevl 5:036a21c44cb7 51 * @param color Pointer to an instance of an Color object
sillevl 5:036a21c44cb7 52 * @ref Color
sillevl 5:036a21c44cb7 53 */
sillevl 6:b5a88296bc50 54
sillevl 2:ed46f45e1d66 55 void setColor(Color* color);
sillevl 5:036a21c44cb7 56
sillevl 5:036a21c44cb7 57 /** Set the color by giving an integer in hexadecimal notation
sillevl 5:036a21c44cb7 58 * @param color Color in hexadecimal notation (hex triplet). 24-bit RGB color as used in web colors.
sillevl 5:036a21c44cb7 59 * @note Each color is made up of 8 bits, 0xRRGGBB
sillevl 5:036a21c44cb7 60 */
sillevl 0:9509f771054b 61 void setColor(int color);
sillevl 5:036a21c44cb7 62
sillevl 5:036a21c44cb7 63 /** Get the current color of the RGB led
sillevl 5:036a21c44cb7 64 * @return instance of Color class containing the current set color
sillevl 5:036a21c44cb7 65 * @ref Color
sillevl 5:036a21c44cb7 66 */
sillevl 2:ed46f45e1d66 67 Color* getColor();
sillevl 4:a7a26506c62f 68
sillevl 0:9509f771054b 69
sillevl 5:036a21c44cb7 70 /// Turn the led off
sillevl 0:9509f771054b 71 void off();
sillevl 0:9509f771054b 72
sillevl 0:9509f771054b 73 private:
sillevl 4:a7a26506c62f 74
sillevl 0:9509f771054b 75 PwmOut* r_out;
sillevl 0:9509f771054b 76 PwmOut* g_out;
sillevl 0:9509f771054b 77 PwmOut* b_out;
sillevl 4:a7a26506c62f 78
sillevl 2:ed46f45e1d66 79 Color* color;
sillevl 4:a7a26506c62f 80
sillevl 2:ed46f45e1d66 81 void setPwmColor(int value, PwmOut* output);
sillevl 4:a7a26506c62f 82
sillevl 0:9509f771054b 83 };
sillevl 2:ed46f45e1d66 84
sillevl 2:ed46f45e1d66 85 #endif