simple RGB led library

Dependents:   m3Dpi MQTT-Thermostat-example Final_project_Tran Final_project_Tran ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RGB.cpp Source File

RGB.cpp

00001 
00002 #include "RGB.h"
00003 
00004 RGB::RGB(PinName r_pin, PinName g_pin, PinName b_pin)
00005 {
00006     r_out = new PwmOut(r_pin);
00007     g_out = new PwmOut(g_pin);
00008     b_out = new PwmOut(b_pin);
00009     off();
00010 }
00011 
00012 RGB::~RGB()
00013 {
00014     delete r_out;
00015     delete g_out;
00016     delete b_out;
00017 }
00018 
00019 void RGB::setColor(Color* color)
00020 {
00021     this->color = color;
00022     setPwmColor(color->getRed(), r_out);
00023     setPwmColor(color->getGreen(), g_out);
00024     setPwmColor(color->getBlue(), b_out);
00025 }
00026 
00027 void RGB::setColor(int color)
00028 {
00029     Color* c = new Color(color);
00030     setColor(c);
00031     delete c;
00032 }
00033 
00034 Color* RGB::getColor()
00035 {
00036     return color;
00037 }
00038 
00039 void RGB::off()
00040 {
00041     Color* color = new Color(0);
00042     setColor(color);
00043     delete color;
00044 }
00045 
00046 void RGB::setPwmColor(int value, PwmOut* output)
00047 {
00048     output->write(((~value) & 0xFF) / 255.0f);
00049 }
00050