Basic RGB library for non-PWM LEDs
Dependents: MenuExample exosite_http_example exosite_http_example FastPWM
Warning : Works with non-PWM LED (0 or 1).
A quick example on how to use it.
#include "mbed.h" #include "RGBLed.h" RGBLed led(LED_RED, LED_GREEN, LED_BLUE); int main() { RGBLed::Color list[8] = {RGBLed::BLACK, RGBLed::RED, RGBLed::GREEN, RGBLed::BLUE, RGBLed::MAGENTA, RGBLed::CYAN, RGBLed::YELLOW, RGBLed::WHITE}; int i = 0; while (true) { i = (i+1)%8; led.setColor(list[i]); wait_ms(100); } }
rgb.h
- Committer:
- rominos2
- Date:
- 2014-09-02
- Revision:
- 0:0969a9e32945
- Child:
- 1:d492c575de97
File content as of revision 0:0969a9e32945:
#include "mbed.h" /** A light RGB LED Class Warning : This library is for non-PWN LED Here is an quick hello-world class that makes the LED blink with all colors. @code #include "mbed.h" #include "rgb.h" RGB led(LED_RED, LED_GREEN, LED_BLUE); int main() { RGB::Color* list[8] = {&RGB::BLACK, &RGB::RED, &RGB::GREEN, &RGB::BLUE, &RGB::MAGENTA, &RGB::CYAN, &RGB::YELLOW, &RGB::WHITE}; int i = 0; while (true) { i = (i+1)%8; led.setColor(list[i]); wait(1); } } @endcode */ class RGB { private: DigitalOut _red; DigitalOut _green; DigitalOut _blue; public: /* RGB Color class Colors have been defined and are ready to use in RGB class */ class Color { private: uint8_t _r; /**< Red component of the Color */ uint8_t _g; /**< Green component of the Color */ uint8_t _b; /**< Blue component of the Color */ Color(uint8_t r, uint8_t g, uint8_t b); /**< Constructor */ friend class RGB; }; /** Create a RBG Object, containing the informations about the RGB pinout. @param redPin the pin linked to the Red LED @param greenPin the pin linked to the green LED @param blue the pin linked to the blue LED */ RGB(PinName redPin, PinName greenPin, PinName bluePin); /** Change the color of the LED. @param color the color (pointer) to display @see RGB::Color */ void setColor(RGB::Color* color); static Color BLACK; /**< Black Color (no color) */ static Color RED; /**< Red Color */ static Color GREEN; /**< Green Color */ static Color BLUE; /**< Blue Color */ static Color MAGENTA; /**< Magenta Color (Red + Blue) */ static Color CYAN; /**< Cyan Color (Green + Blue) */ static Color YELLOW; /**< Yellow Color (Red + Green) */ static Color WHITE; /**< White Color (Red + Green + Blue) */ };