Dependents: NucleoRGB mbed_blinky 4180-lab3 ControlLed ... more
Revision 0:396b3f9574ea, committed 2013-05-24
- Comitter:
- vandep01
- Date:
- Fri May 24 03:21:40 2013 +0000
- Commit message:
- Initial revision of RgbLED class.
Changed in this revision
diff -r 000000000000 -r 396b3f9574ea RGBColor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RGBColor.h Fri May 24 03:21:40 2013 +0000 @@ -0,0 +1,22 @@ + +#ifndef RGBCOLOR_H +#define RGBCOLOR_H + +/** \brief Struct definition for a color made of up of RGB. + */ + struct RGBColor + { + RGBColor() : red(0), green(0), blue(0) + { + } + + RGBColor(const float _red, const float _green, const float _blue) : red(_red), green(_green), blue(_blue) + { + } + + float red; + float green; + float blue; + }; + + #endif // RGBCOLOR_H \ No newline at end of file
diff -r 000000000000 -r 396b3f9574ea RGBLed.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RGBLed.cpp Fri May 24 03:21:40 2013 +0000 @@ -0,0 +1,18 @@ +#include "RGBLed.h" + +RGBLed::RGBLed(PinName redPin, PinName greenPin, PinName bluePin) : m_red(redPin), m_green(greenPin), m_blue(bluePin) +{ +} + +void RGBLed::init() +{ + m_red.period(0.001); +} + +void RGBLed::setColor(const float red, const float green, const float blue) +{ + // Negative logic + m_red = 1.f - red; + m_green = 1.f - green; + m_blue = 1.f - blue; +} \ No newline at end of file
diff -r 000000000000 -r 396b3f9574ea RGBLed.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RGBLed.h Fri May 24 03:21:40 2013 +0000 @@ -0,0 +1,27 @@ +#ifndef RGBLED_H +#define RGBLED_H + +#include "PinNames.h" +#include "mbed.h" + +/** \brief A wrapper for an RGB LED connected to a PWM. This class simplifies the + * setting of the color and also provides some basic color definitions. + */ +class RGBLed +{ +public: + RGBLed(PinName redPin, PinName greenPin, PinName bluePin); + + /** \Brief Initialize the LED */ + void init(); + + /** \Brief Set the color of the RGB LED */ + void setColor(const float red, const float green, const float blue); + +private: + PwmOut m_red; + PwmOut m_green; + PwmOut m_blue; +}; + +#endif \ No newline at end of file