simple RGB led library

Dependents:   m3Dpi MQTT-Thermostat-example Final_project_Tran Final_project_Tran ... more

Embed: (wiki syntax)

« Back to documentation index

RGB Class Reference

RGB Class Reference

RGB class Used to control RGB leds using PWM modulation to dim the individual colors. More...

#include <RGB.h>

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.
ColorgetColor ()
 Get the current color of the RGB led.
void off ()
 Turn the led off.

Detailed Description

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:

  #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;
  }

Definition at line 37 of file RGB.h.


Constructor & Destructor Documentation

RGB ( PinName  r_pin,
PinName  g_pin,
PinName  b_pin 
)

Create a new RGB instance.

Parameters:
r_pinmbed PinName that supports PWM output assigned to the red led
g_pinmbed PinName that supports PWM output assigned to the green led
b_pinmbed PinName that supports PWM output assigned to the blue led

Definition at line 4 of file RGB.cpp.


Member Function Documentation

Color * getColor (  )

Get the current color of the RGB led.

Returns:
instance of Color class containing the current set color Color

Definition at line 34 of file RGB.cpp.

void off (  )

Turn the led off.

Definition at line 39 of file RGB.cpp.

void setColor ( Color color )

Set the color by giving an instance of an Color object.

Parameters:
colorPointer to an instance of an Color object Color

Definition at line 19 of file RGB.cpp.

void setColor ( int  color )

Set the color by giving an integer in hexadecimal notation.

Parameters:
colorColor in hexadecimal notation (hex triplet). 24-bit RGB color as used in web colors.
Note:
Each color is made up of 8 bits, 0xRRGGBB

Definition at line 27 of file RGB.cpp.