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:
Wed Oct 21 17:12:10 2015 +0000
Revision:
3:edc6e64bfc65
Child:
4:a7a26506c62f
RGB fun!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sillevl 3:edc6e64bfc65 1
sillevl 3:edc6e64bfc65 2 #include "EffectManager.h"
sillevl 3:edc6e64bfc65 3
sillevl 3:edc6e64bfc65 4
sillevl 3:edc6e64bfc65 5 EffectManager::EffectManager(RGB* led){
sillevl 3:edc6e64bfc65 6 this->led = led;
sillevl 3:edc6e64bfc65 7 effect = new CycleEffect(led);
sillevl 3:edc6e64bfc65 8 }
sillevl 3:edc6e64bfc65 9
sillevl 3:edc6e64bfc65 10 void EffectManager::next(){
sillevl 3:edc6e64bfc65 11 effectIndex++;
sillevl 3:edc6e64bfc65 12 if(effectIndex > 3) effectIndex = 0;
sillevl 3:edc6e64bfc65 13 switch(effectIndex){
sillevl 3:edc6e64bfc65 14 case 0:
sillevl 3:edc6e64bfc65 15 effect = new PoliceEffect(led);
sillevl 3:edc6e64bfc65 16 break;
sillevl 3:edc6e64bfc65 17 case 1:
sillevl 3:edc6e64bfc65 18 effect = new HeartBeatEffect(led);
sillevl 3:edc6e64bfc65 19 break;
sillevl 3:edc6e64bfc65 20 case 3:
sillevl 3:edc6e64bfc65 21 effect = new CycleEffect(led);
sillevl 3:edc6e64bfc65 22 break;
sillevl 3:edc6e64bfc65 23 }
sillevl 3:edc6e64bfc65 24 }
sillevl 3:edc6e64bfc65 25
sillevl 3:edc6e64bfc65 26 void EffectManager::run(){
sillevl 3:edc6e64bfc65 27 effect->run();
sillevl 3:edc6e64bfc65 28 }