iain galloway / RGBLed-iain

Fork of RGBLed by Romain Berrada

Committer:
rominos2
Date:
Tue Sep 02 13:05:51 2014 +0000
Revision:
0:0969a9e32945
Child:
1:d492c575de97
Initial Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rominos2 0:0969a9e32945 1 #include "mbed.h"
rominos2 0:0969a9e32945 2
rominos2 0:0969a9e32945 3 /** A light RGB LED Class
rominos2 0:0969a9e32945 4 Warning : This library is for non-PWN LED
rominos2 0:0969a9e32945 5
rominos2 0:0969a9e32945 6 Here is an quick hello-world class that makes the LED blink with all colors.
rominos2 0:0969a9e32945 7 @code
rominos2 0:0969a9e32945 8 #include "mbed.h"
rominos2 0:0969a9e32945 9 #include "rgb.h"
rominos2 0:0969a9e32945 10
rominos2 0:0969a9e32945 11 RGB led(LED_RED, LED_GREEN, LED_BLUE);
rominos2 0:0969a9e32945 12
rominos2 0:0969a9e32945 13 int main() {
rominos2 0:0969a9e32945 14 RGB::Color* list[8] = {&RGB::BLACK, &RGB::RED, &RGB::GREEN, &RGB::BLUE, &RGB::MAGENTA, &RGB::CYAN, &RGB::YELLOW, &RGB::WHITE};
rominos2 0:0969a9e32945 15 int i = 0;
rominos2 0:0969a9e32945 16
rominos2 0:0969a9e32945 17 while (true) {
rominos2 0:0969a9e32945 18 i = (i+1)%8;
rominos2 0:0969a9e32945 19 led.setColor(list[i]);
rominos2 0:0969a9e32945 20 wait(1);
rominos2 0:0969a9e32945 21 }
rominos2 0:0969a9e32945 22 }
rominos2 0:0969a9e32945 23 @endcode
rominos2 0:0969a9e32945 24 */
rominos2 0:0969a9e32945 25 class RGB {
rominos2 0:0969a9e32945 26 private:
rominos2 0:0969a9e32945 27 DigitalOut _red;
rominos2 0:0969a9e32945 28 DigitalOut _green;
rominos2 0:0969a9e32945 29 DigitalOut _blue;
rominos2 0:0969a9e32945 30
rominos2 0:0969a9e32945 31 public:
rominos2 0:0969a9e32945 32 /* RGB Color class
rominos2 0:0969a9e32945 33 Colors have been defined and are ready to use in RGB class
rominos2 0:0969a9e32945 34 */
rominos2 0:0969a9e32945 35 class Color {
rominos2 0:0969a9e32945 36 private:
rominos2 0:0969a9e32945 37 uint8_t _r; /**< Red component of the Color */
rominos2 0:0969a9e32945 38 uint8_t _g; /**< Green component of the Color */
rominos2 0:0969a9e32945 39 uint8_t _b; /**< Blue component of the Color */
rominos2 0:0969a9e32945 40 Color(uint8_t r, uint8_t g, uint8_t b); /**< Constructor */
rominos2 0:0969a9e32945 41 friend class RGB;
rominos2 0:0969a9e32945 42 };
rominos2 0:0969a9e32945 43
rominos2 0:0969a9e32945 44 /** Create a RBG Object, containing the informations about the RGB pinout.
rominos2 0:0969a9e32945 45 @param redPin the pin linked to the Red LED
rominos2 0:0969a9e32945 46 @param greenPin the pin linked to the green LED
rominos2 0:0969a9e32945 47 @param blue the pin linked to the blue LED
rominos2 0:0969a9e32945 48 */
rominos2 0:0969a9e32945 49 RGB(PinName redPin, PinName greenPin, PinName bluePin);
rominos2 0:0969a9e32945 50
rominos2 0:0969a9e32945 51 /** Change the color of the LED.
rominos2 0:0969a9e32945 52 @param color the color (pointer) to display
rominos2 0:0969a9e32945 53 @see RGB::Color
rominos2 0:0969a9e32945 54 */
rominos2 0:0969a9e32945 55 void setColor(RGB::Color* color);
rominos2 0:0969a9e32945 56
rominos2 0:0969a9e32945 57 static Color BLACK; /**< Black Color (no color) */
rominos2 0:0969a9e32945 58 static Color RED; /**< Red Color */
rominos2 0:0969a9e32945 59 static Color GREEN; /**< Green Color */
rominos2 0:0969a9e32945 60 static Color BLUE; /**< Blue Color */
rominos2 0:0969a9e32945 61 static Color MAGENTA; /**< Magenta Color (Red + Blue) */
rominos2 0:0969a9e32945 62 static Color CYAN; /**< Cyan Color (Green + Blue) */
rominos2 0:0969a9e32945 63 static Color YELLOW; /**< Yellow Color (Red + Green) */
rominos2 0:0969a9e32945 64 static Color WHITE; /**< White Color (Red + Green + Blue) */
rominos2 0:0969a9e32945 65 };