Ciryk Popeye / RGB-Led
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     this->r_out = new PwmOut(r_pin);
00006     this->g_out = new PwmOut(g_pin);
00007     this->b_out = new PwmOut(b_pin);
00008 }
00009 
00010 void RGB::setColor(Color* color){
00011     this->color = color;
00012     invertColor(color);
00013     r_out->write (this->color->getRed());
00014     g_out->write (this->color->getGreen());
00015     b_out->write (this->color->getBlue());
00016 }
00017 void RGB::setColor(int red, int green, int blue){
00018     this->color = new Color(red,green,blue);
00019 }
00020 void RGB::setColor(int color){
00021     this->color = new Color(color);
00022     
00023 }
00024 void RGB::invertColor(Color* color){
00025     this->color = new Color(
00026         MAX_COLOR_VALUE - color->getRed(),
00027         MAX_COLOR_VALUE - color->getGreen(),
00028         MAX_COLOR_VALUE - color->getBlue()
00029         );
00030 }
00031 void RGB::Off(){
00032     this->color = new Color(0,0,0);
00033 }
00034 
00035 Color* RGB::getColor(){
00036     return this->color;
00037 }