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); } }
RGBLed.cpp
- Committer:
- rominos2
- Date:
- 2014-09-03
- Revision:
- 3:be0a3c2ec426
- Child:
- 4:176363412797
File content as of revision 3:be0a3c2ec426:
#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);