diff options
-rw-r--r-- | Colours.cpp | 22 | ||||
-rw-r--r-- | Colours.h | 3 | ||||
-rw-r--r-- | examples/hue_rotation/hue_rotation.ino | 3 |
3 files changed, 25 insertions, 3 deletions
diff --git a/Colours.cpp b/Colours.cpp index bb77e85..50b782d 100644 --- a/Colours.cpp +++ b/Colours.cpp @@ -6,6 +6,16 @@ #include "Colours.h" Colours::Colours(int rPin,int gPin,int bPin) { + _initPINs(rPin,gPin,bPin); + _invert = false; +} + +Colours::Colours(int rPin,int gPin,int bPin,bool invert) { + _initPINs(rPin,gPin,bPin); + _invert = invert; +} + +void Colours::_initPINs(int rPin,int gPin,int bPin) { _rPin = rPin; _gPin = gPin; _bPin = bPin; @@ -15,9 +25,15 @@ Colours::Colours(int rPin,int gPin,int bPin) { } void Colours::writeRGB(unsigned char r,unsigned char g,unsigned char b) { - analogWrite(_rPin, r); - analogWrite(_gPin, g); - analogWrite(_bPin, b); + if (_invert) { + analogWrite(_rPin, 255-r); + analogWrite(_gPin, 255-g); + analogWrite(_bPin, 255-b); + } else { + analogWrite(_rPin, r); + analogWrite(_gPin, g); + analogWrite(_bPin, b); + } } void Colours::writeHSV(unsigned int h,unsigned char s,unsigned char v) { @@ -10,10 +10,13 @@ class Colours { public: Colours(int rPin,int gPin,int bPin); + Colours(int rPin,int gPin,int bPin,bool invert); void writeRGB(unsigned char r,unsigned char g,unsigned char b); void writeHSV(unsigned int h,unsigned char s,unsigned char v); private: int _rPin,_gPin,_bPin; + bool _invert; + void _initPINs(int rPin,int gPin,int bPin); }; #endif diff --git a/examples/hue_rotation/hue_rotation.ino b/examples/hue_rotation/hue_rotation.ino index 2151618..6e57069 100644 --- a/examples/hue_rotation/hue_rotation.ino +++ b/examples/hue_rotation/hue_rotation.ino @@ -1,6 +1,9 @@ #include <Colours.h> Colours colours(6,5,3); +// For common cathode RGB LEDs comment the line above and uncomment +// the one below. +//Colours colours(6,5,3,true); void setup() { } |