diff options
author | Elena of Valhalla'' Grandi <valhalla@trueelena.org> | 2013-08-14 11:56:37 +0200 |
---|---|---|
committer | Elena of Valhalla'' Grandi <valhalla@trueelena.org> | 2013-08-14 11:56:37 +0200 |
commit | bd7c712d5990548aff35accf2f996c59850924ac (patch) | |
tree | b08442d9a5e67f5a21f9f8a680a59958b7683803 | |
parent | f1b7e9364074571899063e9f668a00eb60d2269a (diff) |
Support for common cathode RGB LEDs
-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() { } |