summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Arduino sketch/serial_rgb.pde28
-rw-r--r--Circuit diagram/RGB.pngbin0 -> 3315 bytes
-rw-r--r--LICENSE7
-rw-r--r--Python code/NEEDED LIBRARIES6
-rwxr-xr-xPython code/rgbled.py85
-rw-r--r--Python code/serialrgb.py36
6 files changed, 162 insertions, 0 deletions
diff --git a/Arduino sketch/serial_rgb.pde b/Arduino sketch/serial_rgb.pde
new file mode 100644
index 0000000..84d331b
--- /dev/null
+++ b/Arduino sketch/serial_rgb.pde
@@ -0,0 +1,28 @@
+#define LEDR 9
+#define LEDG 10
+#define LEDB 11
+
+int r, g, b;
+
+void setup()
+{
+ pinMode(LEDR, OUTPUT);
+ pinMode(LEDG, OUTPUT);
+ pinMode(LEDB, OUTPUT);
+ r = g = b = 0;
+
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ if(Serial.available() >= 3)
+ {
+ r = Serial.read();
+ g = Serial.read();
+ b = Serial.read();
+ }
+ analogWrite(LEDR, r);
+ analogWrite(LEDG, g);
+ analogWrite(LEDB, b);
+}
diff --git a/Circuit diagram/RGB.png b/Circuit diagram/RGB.png
new file mode 100644
index 0000000..9671d48
--- /dev/null
+++ b/Circuit diagram/RGB.png
Binary files differ
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6e0474c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,7 @@
+Copyright (c) 2011 Kevin Chabowski
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Python code/NEEDED LIBRARIES b/Python code/NEEDED LIBRARIES
new file mode 100644
index 0000000..91b993d
--- /dev/null
+++ b/Python code/NEEDED LIBRARIES
@@ -0,0 +1,6 @@
+wxPython:
+ http://www.wxpython.org/
+
+pySerial:
+ http://pyserial.sourceforge.net/
+
diff --git a/Python code/rgbled.py b/Python code/rgbled.py
new file mode 100755
index 0000000..8d699b4
--- /dev/null
+++ b/Python code/rgbled.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from __future__ import division
+import wx, math
+from wx.lib.colourchooser.pycolourchooser import PyColourChooser
+from serialrgb import SerialRGB
+
+def hsv2rgb(h, s, v):
+ h *= 360.0
+ hi = math.floor(h / 60)
+ f = (h / 60) - hi
+ p = v * (1 - s)
+ q = v * (1 - s * f)
+ t = v * (1 - s * (1 - f))
+ if hi == 0 or hi == 6:
+ return (v, t, p)
+ elif hi == 1:
+ return (q, v, p)
+ elif hi == 2:
+ return (p, v, t)
+ elif hi == 3:
+ return (p, q, v)
+ elif hi == 4:
+ return (t, p, v)
+ else:
+ return (v, p, q)
+
+def rgb2hsv(r, g, b):
+ minimum = min([r, g, b])
+ maximum = max([r, g, b])
+ if maximum == minimum:
+ h = 0
+ elif maximum == r:
+ h= 60 * (0 + ((g - b) / (maximum - minimum)))
+ elif maximum == g:
+ h= 60 * (2 + ((b - r) / (maximum - minimum)))
+ else:
+ h= 60 * (4 + ((r - g) / (maximum - minimum)))
+ if h < 0:
+ h += 360
+ s = 0 if maximum == 0 else ((maximum - minimum) / maximum)
+ return (h / 360.0, s, maximum)
+
+class rgbled_frame(wx.Frame):
+ def __init__(self, rgbled):
+ wx.Frame.__init__(self, None, title="RGBLED", size=(500, 300))
+ self.rgbled = rgbled
+
+ mainpanel = wx.Panel(self, -1)
+
+ self.cpctrl = PyColourChooser(mainpanel, -1)
+ self.cpctrl.SetValue(wx.Colour(0,0,0,255))
+
+ self.timer = wx.Timer(self)
+
+ self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
+ self.timer.Start(100)
+
+ def on_timer(self, evt):
+ colour = self.cpctrl.GetValue()
+ r = colour.Red()
+ g = colour.Green()
+ b = colour.Blue()
+ if isinstance(self.rgbled, SerialRGB):
+ self.rgbled.change_color((r, g, b))
+
+class rgbled_app(wx.App):
+ def OnInit(self):
+ self.rgbled = None
+ portdlg = wx.TextEntryDialog(None, "Serial port:")
+ if portdlg.ShowModal() == wx.ID_OK:
+ self.rgbled = SerialRGB(portdlg.GetValue())
+ frame = rgbled_frame(self.rgbled)
+ portdlg.Destroy()
+ frame.Show()
+ self.SetTopWindow(frame)
+ return True
+ def OnExit(self):
+ if isinstance(self.rgbled,SerialRGB):
+ self.rgb2hsv.close_connection()
+
+if __name__ == '__main__':
+ myapp = rgbled_app()
+ myapp.MainLoop()
diff --git a/Python code/serialrgb.py b/Python code/serialrgb.py
new file mode 100644
index 0000000..7296e22
--- /dev/null
+++ b/Python code/serialrgb.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import serial
+
+class SerialRGB(object):
+ """Easy controlling of the RGB-LED / Arduino"""
+ def __init__(self, addr, baud=9600):
+ """
+ Creating a new SerialRGB object.
+
+ addr -- The address of the serial port.
+ baud -- The baudrate (default: 9600)
+ """
+ try:
+ self.ser = serial.Serial(addr, baud)
+ except:
+ raise IOError("Could not connect to Arduino via serial port.")
+
+ def __del__(self):
+ self.close_connection()
+
+ def change_color(self, color):
+ """
+ Send a colot to the Arduino.
+
+ color - 3-Tuple representing an RGB-Color (color components must be in range 0 - 255).
+ """
+ r, g, b = color
+ self.ser.write(chr(r) + chr(g) + chr(b))
+
+ def close_connection(self):
+ """Closes the connection to the Arduino."""
+ if self.ser is not None:
+ self.ser.close()
+ self.ser = None