Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 144 lines (121 sloc) 5.214 kb
d8a7a0b @CCDKP Initial Commit
authored
1 #ifndef __LIGHTWALL_H
2 #define __LIGHTWALL_H
3 #include <WProgram.h>
4 /*
5 Lightwall Library
6 This code controls a series of GE Color-effects lights.
7 It uses Analog pins 0-3 and Digital pins 4-7 for output.
8
9 Written by Chris Cooper (CCooper@QCCoLab.com, @CC_DKP)
10 Derived from the reference implementation by Mark Kruse
11 Based on the research by Robert "Darco" Quattlebaum (http://www.deepdarc.com/2010/11/27/hacking-christmas-lights/)
12
13 Designed for the QC Co-Lab Hackerspace
14 Http://www.qccolab.com
15
16 Copyright 2011 Chris Cooper
17
18 Licensed under the Apache License, Version 2.0 (the "License");
19 you may not use this file except in compliance with the License.
20 You may obtain a copy of the License at
21
22 http://www.apache.org/licenses/LICENSE-2.0
23
24 Unless required by applicable law or agreed to in writing, software
25 distributed under the License is distributed on an "AS IS" BASIS,
26 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 See the License for the specific language governing permissions and
28 limitations under the License.
29
30 */
31
32 // These are used to adjust the internal timings during output.
33 // Depending on the tolerances of individual bulbs you may need to adjust these.
34 #define START_BLIP PORTD = 0xFF; _delay_us(10);
35 #define START_NUM PORTD = 0x00; _delay_us(10);
36 #define START_BRIGHT PORTD = 0x00; _delay_us(10);
37 #define START_COLOR PORTD = 0x00; _delay_us(10);
38
39 #define OUT_ONE PORTD = 0x00; _delay_us(10);
40 #define OUT_ZERO PORTD = 0xFF; _delay_us(10);
41 #define OUT_VAR(var) PORTD = var; _delay_us(10);
42
43 #define STOP_BIT PORTD = 0xFF; _delay_us(10);
44 #define STOP_BLIP PORTD = 0x00;
45
46 #define DEFAULT_INTENSITY (0xCC)
47
48
49 class LightWall {
50 public:
51
52 /*
53 * This array is the data transmitted directly onto the bus using digital pins 0-7.
54 * Once the lightwall is intialized, Serial Bus transmission will be blocked.
55 *
56 * To keep speed up, we transmit to the same addres on 8 strings simultaneously.
57 *
58 * All 8 strings are multiplexed into a single byte.
59 * Pin: 76543210
60 * Bit: 87654321
61 *
62 * The lights use 12-bit color, so we need 12 bytes.
63 * The bits are ordered 4 Blue, 4 Green, 4 Red, most significant bit first
64 *
65 * The data bus is inverted, so the data going in must be inverted as well,
66 */
67 uint8_t Buffer[12];
68
69 // Prior to initializtion and addressing, a 30 second delay is introduced to provide time
70 // to reprogram the arduino.
71 LightWall(void);
72 ~LightWall(void);
73 void begin(uint8_t lightsPerString, uint8_t lightsPerRow);
74
75 void fadeout(uint16_t time);// fade to black over time (in ms) (leaves intesity at 0)
76 void fadein(uint16_t time);// fade in to default intensitiy over time (in ms)
77 void fadein(uint16_t time, uint8_t intensity);// fade in to newIntensity over time (in ms)
78 void blank_screen();//Fills screen with Black
79 void set_intensity(uint8_t intensity);
80 uint8_t lightsPerString();
81 uint8_t lightsPerRow();
82
83 /*Sends the data loaded in Buffer[] out to the address "num" on all 8 channels simultaneously
84 * You must wait at least 30 uSeconds between frames
85 *
86 * It is important to distinguish that this does not send an entire image "frame" of video, but
87 * rather the required data for 1 pixel on each of the 8 data channels.
88 *
89 * From: http://www.deepdarc.com/2010/11/27/hacking-christmas-lights/
90 * The protocol on the data line is simple and self-clocked. Here are the low-level details:
91 *
92 * Idle bus state: Low
93 * Start Bit: High for 10 uSeconds
94 * 0 Bit: Low for 10 uSeconds, High for 20 uSeconds
95 * 1 Bit: Low for 20 uSeconds, High for 10 uSeconds
96 * Minimum quiet-time between frames: 30 uSeconds
97 * Each frame is 26 bits long and has the following format:
98 *
99 * Start bit
100 * 6-Bit Bulb Address, MSB first
101 * 8-Bit Brightness, MSB first
102 * 4-Bit Blue, MSB first
103 * 4-Bit Green, MSB first
104 * 4-Bit Red, MSB first
105 *
106 * It appears as if the lights are clocked off the falling edge.
107 * Data is tested half-way between clocks.
108 */
109 void send_frame(uint8_t address);
110
111 private:
112 uint8_t LPS;
113 uint8_t LPR;
114 uint8_t intensity;
115
116
117 /*
118 * On first power, all lights stop forwarding data and enter learning mode.
119 * The first non-broadcast packet they see sets their address, after which
120 * they begin forwarding data packets.
121 *
122 * To initialize the string, we walk through the lights,
123 * sending the desired address out in *physical* connection order.
124 * We assume a serpentine pattern, starting with the 00 and reversing after
125 * lightsPerRow until lightsPerString is reached.
126 *
127 * QC Co-Lab's Strings are configured with 30 Lights each.
128 * There are 15 lights per row, with each row wired in the opposite direction.
129 * Physical Layout:
130 * [00][01][02][03][04][05][06][07][08][09][10][11][12][13][14]
131 * )
132 * [29][28][27][26][25][24][23][22][21][20][19][18][17][16][15]
133 *
134 * Logical Layout after addressing:
135 * [00][01][02][03][04][05][06][07][08][09][10][11][12][13][14]
136 * [15][16][17][18][19][20][21][22][23][24][25][26][27][28][29]
137 *
138 */
139 void address_lights();
140 };
141
142 #endif
143
Something went wrong with that request. Please try again.