Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New.

  • Loading branch information...
commit 1eb81346f7120364fad258be255bbe4ba95b0c34 0 parents
@sowbug authored
116 G35.cpp
@@ -0,0 +1,116 @@
+/*
+ G35: An Arduino library for GE Color Effects G-35 holiday lights.
+ Copyright © 2011 The G35 Authors. Use, modification, and distribution are
+ subject to the BSD license as described in the accompanying LICENSE file.
+
+ Original version by Paul Martis (http://www.digitalmisery.com). See
+ README for complete attributions.
+*/
+
+#include <WProgram.h>
+#include <G35.h>
+
+G35::G35(int pin, int light_count) {
+ pinMode(pin, OUTPUT);
+ _pin = pin;
+ _light_count = light_count;
+}
+
+// The timings below have been hand-tuned. Adjust if necessary.
+void G35::begin() {
+ digitalWrite(_pin, HIGH);
+ delayMicroseconds(6); // Output should be ~ 10uS long
+ digitalWrite(_pin, LOW);
+}
+
+void G35::one() {
+ digitalWrite(_pin, LOW);
+ delayMicroseconds(12); // Output should be ~ 20uS long
+ digitalWrite(_pin, HIGH);
+ delayMicroseconds(6); // Output should be ~ 10uS long
+ digitalWrite(_pin, LOW);
+}
+
+void G35::zero() {
+ digitalWrite(_pin, LOW);
+ delayMicroseconds(2); // Output should be ~ 10uS long
+ digitalWrite(_pin, HIGH);
+ delayMicroseconds(17); // Output should be ~ 20uS long
+ digitalWrite(_pin, LOW);
+}
+
+void G35::end() {
+ digitalWrite(_pin, LOW);
+ delayMicroseconds(30); // Quiet time should be ~ 30us long
+}
+
+// Turn on a specific LED with a color and brightness
+void G35::set_color(uint8_t led, uint8_t intensity, color_t color) {
+ uint8_t i;
+ begin();
+ for (i = 6; i; i--, (led <<= 1)) {
+ if (led & (1 << 5)) {
+ one();
+ } else {
+ zero();
+ }
+ }
+ for (i = 8; i; i--, (intensity <<=1 )) {
+ if (intensity & (1 << 7)) {
+ one();
+ } else {
+ zero();
+ }
+ }
+
+ for (i=12; i; i--, (color <<= 1)) {
+ if (color & (1 << 11)) {
+ one();
+ } else {
+ zero();
+ }
+ }
+ end();
+}
+
+// Returns 12-bit color from red, green, and blue components
+color_t G35::color(uint8_t r, uint8_t g, uint8_t b) {
+ return COLOR(r, g, b);
+}
+
+// Returns primary hue colors
+color_t G35::color_hue(uint8_t h) {
+ switch (h >> 4) {
+ case 0: h -= 0; return color(h, CHANNEL_MAX, 0);
+ case 1: h -= 16; return color(CHANNEL_MAX, (CHANNEL_MAX - h), 0);
+ case 2: h -= 32; return color(CHANNEL_MAX, 0, h);
+ case 3: h -= 48; return color((CHANNEL_MAX - h), 0, CHANNEL_MAX);
+ case 4: h -= 64; return color(0, h, CHANNEL_MAX);
+ case 5: h -= 80; return color(0, CHANNEL_MAX, (CHANNEL_MAX - h));
+ }
+}
+
+// Make all LEDs the same color starting at specified beginning LED
+void G35::fill_color(uint8_t begin, uint8_t count,
+ uint8_t intensity, color_t color) {
+ while (count--) {
+ set_color(begin++, intensity, color);
+ }
+}
+
+// Make all LEDs the same color
+void G35::fill_color_same(uint8_t begin, uint8_t count,
+ uint8_t intensity, color_t color) {
+ while (count--) {
+ set_color(0, intensity, color);
+ }
+}
+
+// Initialize string for individual bulb addressing
+void G35::enumerate() {
+ uint8_t i;
+ while (i < _light_count) {
+ fill_color(0, _light_count, DEFAULT_INTENSITY, COLOR_BLACK);
+ ++i;
+ }
+}
66 G35.h
@@ -0,0 +1,66 @@
+/*
+ G35: An Arduino library for GE Color Effects G-35 holiday lights.
+ Copyright © 2011 The G35 Authors. Use, modification, and distribution are
+ subject to the BSD license as described in the accompanying LICENSE file.
+
+ Original version by Paul Martis (http://www.digitalmisery.com). See
+ README for complete attributions.
+*/
+
+#ifndef INCLUDE_G35_ARDUINO_H
+#define INCLUDE_G35_ARDUINO_H
+
+#include <WProgram.h>
+
+#define color_t uint16_t
+#define CHANNEL_MAX (0xF) // Each color channel is 4-bit
+#define DEFAULT_INTENSITY (0xCC) // Brightness is 8-bit
+#define HUE_MAX ((CHANNEL_MAX+1)*6-1)
+
+// Color is 12-bit (4-bit each R, G, B)
+#define COLOR(r,g,b) ((r)+((g)<<4)+((b)<<8))
+#define COLOR_WHITE COLOR(CHANNEL_MAX,CHANNEL_MAX,CHANNEL_MAX)
+#define COLOR_BLACK COLOR(0,0,0)
+#define COLOR_RED COLOR(CHANNEL_MAX,0,0)
+#define COLOR_GREEN COLOR(0,CHANNEL_MAX,0)
+#define COLOR_BLUE COLOR(0,0,CHANNEL_MAX)
+#define COLOR_CYAN COLOR(0,CHANNEL_MAX,CHANNEL_MAX)
+#define COLOR_MAGENTA COLOR(CHANNEL_MAX,0,CHANNEL_MAX)
+#define COLOR_YELLOW COLOR(CHANNEL_MAX,CHANNEL_MAX,0)
+#define COLOR_PURPLE COLOR(0xa,0x3,0xd)
+#define COLOR_ORANGE COLOR(0xf,0x1,0x0)
+#define COLOR_WARMWHITE COLOR(0xf,0x7,0x2)
+
+class G35 {
+ public:
+ // Arduino Pin # and total lights on string
+ G35(int pin, int light_count);
+
+ // Turn on a specific LED
+ void set_color(uint8_t led, uint8_t intensity, color_t color);
+
+ // Color data type
+ color_t color(uint8_t r, uint8_t g, uint8_t b);
+
+ color_t color_hue(uint8_t h);
+
+ void fill_color(uint8_t begin, uint8_t count, uint8_t intensity,
+ color_t color);
+
+ // Make all LEDs the same color
+ void fill_color_same(uint8_t begin, uint8_t count, uint8_t intensity,
+ color_t color);
+
+ // Need to enumerate in order to address individual LEDs
+ void enumerate();
+ private:
+ // Low-level one-wire protocol commands
+ void begin();
+ void one();
+ void zero();
+ void end();
+ int _pin;
+ int _light_count;
+};
+
+#endif // INCLUDE_G35_ARDUINO_H
26 LICENSE
@@ -0,0 +1,26 @@
+Copyright 2011 The G35 Authors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE G35 AUTHORS "AS IS" AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE G35 AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+The views and conclusions contained in the software and documentation are
+those of the authors and should not be interpreted as representing official
+policies, either expressed or implied, of The G35 Authors.
4 README
@@ -0,0 +1,4 @@
+Based on Christmas Light Control by Robert Quattlebaum <darco@deepdarc.com>
+(http://www.deepdarc.com/2010/11/27/hacking-christmas-lights)
+and Arduino adaptation by Scott Harris <scottrharris@gmail.com>
+http://scottrharris.blogspot.com/2010/12/controlling-ge-color-effects-lights.html
37 examples/BasicExample/BasicExample.pde
@@ -0,0 +1,37 @@
+#include <G35.h>
+
+#define OUT_PIN 19 // Arduino pin #
+#define LIGHT_COUNT 50 // Total # of lights on string (usually 50, 48, or 36)
+
+static uint16_t c;
+
+G35 lights(OUT_PIN, LIGHT_COUNT); // Constructor
+
+void setup() {
+ // Enumerate lights on string to enable individual bulb addressing
+ lights.enumerate();
+}
+
+void loop() {
+ // fill_color makes all bulbs from 0 to LIGHT_COUNT the same brightness
+ // and color
+ lights.fill_color(0, LIGHT_COUNT, DEFAULT_INTENSITY, COLOR_RED);
+
+ delay(1000);
+
+ lights.fill_color(0, LIGHT_COUNT, DEFAULT_INTENSITY, COLOR_GREEN);
+
+ delay(1000);
+
+ // set_color addresses one specific bulb at a time with brightness and
+ // color setting
+ for (int i = 0; i < LIGHT_COUNT / 2; ++i) {
+ color_t color = lights.color_hue((i + c) % (HUE_MAX + 1));
+ lights.set_color(i, DEFAULT_INTENSITY, color);
+ lights.set_color(LIGHT_COUNT - 1 - i, DEFAULT_INTENSITY, color);
+ }
+
+ ++c;
+
+ delay(1000);
+}
7 keywords.txt
@@ -0,0 +1,7 @@
+GEColorEffects KEYWORD1
+set_color KEYWORD2
+color KEYWORD2
+color_hue KEYWORD2
+fill_color KEYWORD2
+fill_color_same KEYWORD2
+enumerate KEYWORD2
Please sign in to comment.
Something went wrong with that request. Please try again.