Reiko Randoja / Mbed 2 deprecated ut_bbr

Dependencies:   USBDevice mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RGBLed.cpp Source File

RGBLed.cpp

00001 #include "RGBLed.hpp"
00002 
00003 RGBLed::RGBLed(PinName rPin, PinName gPin, PinName bPin) :
00004     r(rPin),
00005     g(gPin),
00006     b(bPin)
00007 {
00008     set(false, false, false);
00009 }
00010 
00011 bool RGBLed::getRed()
00012 {
00013     return !r.read();
00014 }
00015 
00016 bool RGBLed::getGreen()
00017 {
00018     return !g.read();
00019 }
00020 
00021 bool RGBLed::getBlue()
00022 {
00023     return !b.read();
00024 }
00025 
00026 RGBLed::Color RGBLed::get()
00027 {
00028     return Color(getRed() | (getGreen() << 1) | (getBlue() << 2));
00029 }
00030 
00031 RGBLed& RGBLed::setRed(bool value)
00032 {
00033     r = !value;
00034     return *this;
00035 }
00036 
00037 RGBLed& RGBLed::setGreen(bool value)
00038 {
00039     g = !value;
00040     return *this;
00041 }
00042 
00043 RGBLed& RGBLed::setBlue(bool value)
00044 {
00045     b = !value;
00046     return *this;
00047 }
00048 
00049 RGBLed& RGBLed::set(bool rValue, bool gValue, bool bValue)
00050 {
00051     return setRed(rValue).setGreen(gValue).setBlue(bValue);
00052 }
00053 
00054 RGBLed& RGBLed::set(RGBLed::Color color)
00055 {
00056     return set(color & 1, color & 2, color & 4);
00057 }