With this RGB class you can control a RGB-LED. You can also control a RGB-LED with a Color object.
Revision 0:b6d24e2f118b, committed 2015-12-25
- Comitter:
- de_geeter_alexander
- Date:
- Fri Dec 25 20:15:13 2015 +0000
- Commit message:
- Rgb classe voor het besturen van een RGB led
Changed in this revision
rgb.cpp | Show annotated file Show diff for this revision Revisions of this file |
rgb.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r b6d24e2f118b rgb.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rgb.cpp Fri Dec 25 20:15:13 2015 +0000 @@ -0,0 +1,32 @@ +#include "rgb.h" + +RGB::RGB(PinName r_pin, PinName g_pin, PinName b_pin){ + this->r_out=new PwmOut(r_pin); + this->g_out=new PwmOut(g_pin); + this->b_out=new PwmOut(b_pin); + setColor(0,0,0); + } + +void RGB::setColor(int red, int green, int blue){ + r_out->write(1.0-toFloat(red)); + g_out->write(1.0-toFloat(green)); + b_out->write(1.0-toFloat(blue)); + } + +void RGB::setColor(int color){ + Color kleur=Color(color); + r_out->write(1.0-toFloat(kleur.getRed())); + g_out->write(1.0-toFloat(kleur.getGreen())); + b_out->write(1.0-toFloat(kleur.getBlue())); + } + +void RGB::setColor(Color color){ + r_out->write(toFloat(color.getRed())); + g_out->write(toFloat(color.getGreen())); + b_out->write(toFloat(color.getBlue())); + } + + +float RGB::toFloat (int floater){ + return (float) ((floater)/255.0f); + } \ No newline at end of file
diff -r 000000000000 -r b6d24e2f118b rgb.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rgb.h Fri Dec 25 20:15:13 2015 +0000 @@ -0,0 +1,25 @@ +#ifndef RGB_H +#define RGB_H +#include "mbed.h" +#include "color.h" +#include "LM75B.h" + +class RGB{ + + + public: + + RGB(PinName r_pin, PinName g_pin, PinName b_pin); + void setColor(Color color); + void setColor(int red, int green, int blue); + void setColor(int color); + void off(); + + private: + PwmOut* r_out; + PwmOut* g_out; + PwmOut* b_out; + float toFloat(int floater); + }; + +#endif \ No newline at end of file