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

Revision:
6:b5a88296bc50
Parent:
4:a7a26506c62f
Parent:
5:036a21c44cb7
--- a/RGB.h	Thu Oct 22 17:17:13 2015 +0000
+++ b/RGB.h	Thu Nov 19 08:16:58 2015 +0000
@@ -5,26 +5,73 @@
 #ifndef RGB_H
 #define RGB_H
 
-class RGB
-{
-public:
 
+/** RGB class
+ *  Used to control RGB leds using PWM modulation to dim the individual colors. 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)
+ *  Example usage:
+ *  @code
+ *
+ *  #include "mbed.h"
+ *  #include "RGB.h"
+ *  RGB led(p23,p24,p25);
+ *  
+ *  void main(){
+ *      led.off();
+ *      
+ *      wait(1.0);
+ *      
+ *      // setting the color using the Color enum with named colors
+ *      led.setColor(Color::RED);   
+ *      
+ *      // setting the color using a hexadecimal notated integer (yellow)
+ *      led.setColor(0xFFFF00);
+ *      
+ *      // setting the color using an instance of the Color class
+ *      Color* myColor = new Color(0.0,1.0,0.0);
+ *      led.setColor(myColor);
+ *      delete myColor;
+ *  }
+ *  @endcode
+ */
+class RGB{
+    public:
+    
     static const int OFF = 0;
 
+    /** Create a new RGB instance
+     *  @param r_pin mbed PinName that supports PWM output assigned to the red led
+     *  @param g_pin mbed PinName that supports PWM output assigned to the green led
+     *  @param b_pin mbed PinName that supports PWM output assigned to the blue led
+     */
     RGB(PinName r_pin, PinName g_pin, PinName b_pin);
     ~RGB();
-    // void setIntensity(int intensity); // How are we gonna do this?
+
+    /** Set the color by giving an instance of an Color object
+     *  @param color Pointer to an instance of an Color object
+     *  @ref Color
+     */
+
     void setColor(Color* color);
+    
+    /** Set the color by giving an integer in hexadecimal notation
+     *  @param color Color in hexadecimal notation (hex triplet). 24-bit RGB color as used in web colors.
+     *  @note Each color is made up of 8 bits, 0xRRGGBB
+     */
     void setColor(int color);
+    
+    /** Get the current color of the RGB led
+     *  @return instance of Color class containing the current set color
+     *  @ref Color
+     */
     Color* getColor();
 
-    // void on(); // do we need this? what value to turn on to?
+    
+    /// Turn the led off
     void off();
+    
+    private:
 
-protected:
-    //void setColor(int r, int g, int b);
-
-private:
     PwmOut* r_out;
     PwmOut* g_out;
     PwmOut* b_out;