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
- Committer:
- rominos2
- Date:
- 2014-09-02
- Revision:
- 0:0969a9e32945
- Child:
- 2:3c0889914cb2
File content as of revision 0:0969a9e32945:
#include "rgb.h" RGB::Color::Color(uint8_t r, uint8_t g, uint8_t b) : _r(r), _g(g), _b(b) { } RGB::RGB(PinName redPin, PinName greenPin, PinName bluePin) : _red(redPin), _green(greenPin), _blue(bluePin) { this->setColor(&RGB::BLACK); // Clear the LED output } void RGB::setColor(Color* color) { _red = color->_r; _green = color->_g; _blue = color->_b; } RGB::Color RGB::BLACK = RGB::Color(1,1,1); RGB::Color RGB::RED = RGB::Color(0,1,1); RGB::Color RGB::GREEN = RGB::Color(1,0,1); RGB::Color RGB::BLUE = RGB::Color(1,1,0); RGB::Color RGB::MAGENTA = RGB::Color(0,1,0); RGB::Color RGB::CYAN = RGB::Color(1,0,0); RGB::Color RGB::YELLOW = RGB::Color(0,0,1); RGB::Color RGB::WHITE = RGB::Color(0,0,0);