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); } }
Diff: RGBLed.cpp
- Revision:
- 3:be0a3c2ec426
- Child:
- 4:176363412797
diff -r 3c0889914cb2 -r be0a3c2ec426 RGBLed.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RGBLed.cpp Wed Sep 03 10:13:45 2014 +0000 @@ -0,0 +1,23 @@ +#include "RGBLed.h" + +RGBLed::Color::Color(bool r, bool g, bool b) : _r(r), _g(g), _b(b) { +} + +RGBLed::RGBLed(PinName redPin, PinName greenPin, PinName bluePin) : _red(redPin), _green(greenPin), _blue(bluePin) { + this->setColor(RGBLed::BLACK); // Clear the LED output +} + +void RGBLed::setColor(Color& color) { + _red = color._r; + _green = color._g; + _blue = color._b; +} + +RGBLed::Color RGBLed::BLACK = RGBLed::Color(1,1,1); +RGBLed::Color RGBLed::RED = RGBLed::Color(0,1,1); +RGBLed::Color RGBLed::GREEN = RGBLed::Color(1,0,1); +RGBLed::Color RGBLed::BLUE = RGBLed::Color(1,1,0); +RGBLed::Color RGBLed::MAGENTA = RGBLed::Color(0,1,0); +RGBLed::Color RGBLed::CYAN = RGBLed::Color(1,0,0); +RGBLed::Color RGBLed::YELLOW = RGBLed::Color(0,0,1); +RGBLed::Color RGBLed::WHITE = RGBLed::Color(0,0,0); \ No newline at end of file