summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Colours.cpp86
-rw-r--r--src/Colours.h38
-rw-r--r--src/examples/hue_rotation/hue_rotation.ino27
-rw-r--r--src/examples/wtfpl-2.txt14
-rw-r--r--src/keywords.txt3
5 files changed, 168 insertions, 0 deletions
diff --git a/src/Colours.cpp b/src/Colours.cpp
new file mode 100644
index 0000000..7ae49a2
--- /dev/null
+++ b/src/Colours.cpp
@@ -0,0 +1,86 @@
+/*
+ * Colours - library for managing the colours on RGB LEDs
+ * Copyright 2009, 2013 Elena Grandi
+ *
+ * This file is part of Colours.
+ *
+ * Colours is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * Colours is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Colours. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Arduino.h"
+#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;
+ pinMode(_rPin,OUTPUT);
+ pinMode(_gPin,OUTPUT);
+ pinMode(_bPin,OUTPUT);
+}
+
+void Colours::writeRGB(unsigned char r,unsigned char g,unsigned char 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) {
+ h = h % 360;
+ if (s==0) {
+ writeRGB(v,v,v);
+ } else {
+ unsigned int f,p,q,t;
+ f = 256*(h%60)/60;
+ p = v*(256-s)/256;
+ q = v*(256-f*s/256)/256;
+ t = v*(256-s*(256-f)/256)/256;
+ switch( (h/60) % 6 ) {
+ case 0:
+ writeRGB(v,t,p);
+ break;
+ case 1:
+ writeRGB(q,v,p);
+ break;
+ case 2:
+ writeRGB(p,v,t);
+ break;
+ case 3:
+ writeRGB(p,q,v);
+ break;
+ case 4:
+ writeRGB(t,p,v);
+ break;
+ case 5:
+ writeRGB(v,p,q);
+ break;
+ }
+ }
+}
diff --git a/src/Colours.h b/src/Colours.h
new file mode 100644
index 0000000..421dfc9
--- /dev/null
+++ b/src/Colours.h
@@ -0,0 +1,38 @@
+/*
+ * Colours - library for managing the colours on RGB LEDs
+ * Copyright 2009, 2013 Elena Grandi
+ *
+ * This file is part of Colours.
+ *
+ * Colours is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * Colours is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Colours. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef COLOURS_h
+#define COLOURS_h
+
+#include "Arduino.h"
+
+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/src/examples/hue_rotation/hue_rotation.ino b/src/examples/hue_rotation/hue_rotation.ino
new file mode 100644
index 0000000..00a48d7
--- /dev/null
+++ b/src/examples/hue_rotation/hue_rotation.ino
@@ -0,0 +1,27 @@
+/*
+ * hue_rotation - Cycle an RGB LED through hue values.
+ * Copyright 2009, 2013 Elena Grandi
+ *
+ * This work is free. You can redistribute it and/or modify it under the
+ * terms of the Do What The Fuck You Want To Public License, Version 2,
+ * as published by Sam Hocevar. See the examples/wtfpl-2.txt file
+ * for more details.
+ */
+
+#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() {
+}
+
+void loop() {
+ int h;
+ for (h=0;h<360;h++) {
+ colours.writeHSV(h,255,255);
+ delay(50);
+ }
+}
diff --git a/src/examples/wtfpl-2.txt b/src/examples/wtfpl-2.txt
new file mode 100644
index 0000000..ee7d6a5
--- /dev/null
+++ b/src/examples/wtfpl-2.txt
@@ -0,0 +1,14 @@
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
+
diff --git a/src/keywords.txt b/src/keywords.txt
new file mode 100644
index 0000000..92dd91d
--- /dev/null
+++ b/src/keywords.txt
@@ -0,0 +1,3 @@
+Colours KEYWORD1
+writeRGB KEYWORD2
+writeHSV KEYWORD2