summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena of Valhalla'' Grandi <valhalla@trueelena.org>2013-08-14 11:56:37 +0200
committerElena of Valhalla'' Grandi <valhalla@trueelena.org>2013-08-14 11:56:37 +0200
commitbd7c712d5990548aff35accf2f996c59850924ac (patch)
treeb08442d9a5e67f5a21f9f8a680a59958b7683803
parentf1b7e9364074571899063e9f668a00eb60d2269a (diff)
Support for common cathode RGB LEDs
-rw-r--r--Colours.cpp22
-rw-r--r--Colours.h3
-rw-r--r--examples/hue_rotation/hue_rotation.ino3
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) {
diff --git a/Colours.h b/Colours.h
index cd08bfc..c91b30a 100644
--- a/Colours.h
+++ b/Colours.h
@@ -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() {
}