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.cpp@2:3c0889914cb2, 2014-09-02 (annotated)
- Committer:
- rominos2
- Date:
- Tue Sep 02 21:55:22 2014 +0000
- Revision:
- 2:3c0889914cb2
- Parent:
- 0:0969a9e32945
Change from pointer to reference for the setColor method.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rominos2 | 0:0969a9e32945 | 1 | #include "rgb.h" |
rominos2 | 0:0969a9e32945 | 2 | |
rominos2 | 0:0969a9e32945 | 3 | RGB::Color::Color(uint8_t r, uint8_t g, uint8_t b) : _r(r), _g(g), _b(b) { |
rominos2 | 0:0969a9e32945 | 4 | } |
rominos2 | 0:0969a9e32945 | 5 | |
rominos2 | 0:0969a9e32945 | 6 | RGB::RGB(PinName redPin, PinName greenPin, PinName bluePin) : _red(redPin), _green(greenPin), _blue(bluePin) { |
rominos2 | 2:3c0889914cb2 | 7 | this->setColor(RGB::BLACK); // Clear the LED output |
rominos2 | 0:0969a9e32945 | 8 | } |
rominos2 | 0:0969a9e32945 | 9 | |
rominos2 | 2:3c0889914cb2 | 10 | void RGB::setColor(Color& color) { |
rominos2 | 2:3c0889914cb2 | 11 | _red = color._r; |
rominos2 | 2:3c0889914cb2 | 12 | _green = color._g; |
rominos2 | 2:3c0889914cb2 | 13 | _blue = color._b; |
rominos2 | 0:0969a9e32945 | 14 | } |
rominos2 | 0:0969a9e32945 | 15 | |
rominos2 | 0:0969a9e32945 | 16 | RGB::Color RGB::BLACK = RGB::Color(1,1,1); |
rominos2 | 0:0969a9e32945 | 17 | RGB::Color RGB::RED = RGB::Color(0,1,1); |
rominos2 | 0:0969a9e32945 | 18 | RGB::Color RGB::GREEN = RGB::Color(1,0,1); |
rominos2 | 0:0969a9e32945 | 19 | RGB::Color RGB::BLUE = RGB::Color(1,1,0); |
rominos2 | 0:0969a9e32945 | 20 | RGB::Color RGB::MAGENTA = RGB::Color(0,1,0); |
rominos2 | 0:0969a9e32945 | 21 | RGB::Color RGB::CYAN = RGB::Color(1,0,0); |
rominos2 | 0:0969a9e32945 | 22 | RGB::Color RGB::YELLOW = RGB::Color(0,0,1); |
rominos2 | 0:0969a9e32945 | 23 | RGB::Color RGB::WHITE = RGB::Color(0,0,0); |