SHOW:
|
|
- or go back to the newest paste.
1 | /* HAPPY HOLIDAYS TO ALL ARDUINOS !!! */ | |
2 | ||
3 | //modified from http://pastebin.com/wUSVNubd | |
4 | ||
5 | /* | |
6 | RadioShack RGB Color LED strip light show for TM1803 LED controlled LEDs. | |
7 | This began with the default code from RS - now with some annotations to help explain | |
8 | what is happening PLUS several NEW Patterns for July 4th 2014 and a change in the | |
9 | pulse timing to make it easier to adjust for MCU cycle speed (e.g. 8MHz vs 16 MHz); | |
10 | */ | |
11 | ||
12 | #include <avr/pgmspace.h> | |
13 | // This is a "standard" include for the Arduino IDE that provides functions needed (like PROGMEM, etc.) | |
14 | ||
15 | /* | |
16 | #define DATA_1 (PORTD |= (1<<5)) // Set logic high Pin5 of Port D | |
17 | #define DATA_0 (PORTD &= ~(1<<5)) // Set Pin5 logic low Pin5 of Port D | |
18 | #define STRIP_PINOUT DDRD |= (1<<5) // Set Pin5 of PortD as digital output | |
19 | #define LED_RGB_STRIP | |
20 | */ | |
21 | ||
22 | #define DATA_1 (PORTC |= 0X01) // DEFINE a value for DATA as 1 // for UNO | |
23 | #define DATA_0 (PORTC &= 0XFE) // DEFINE a value for DATA 0 // for UNO | |
24 | #define STRIP_PINOUT (DDRC=0x3F) // DEFINE PORTC as OUTPUT // for UNO (change pins 0-5; leave PORTC 6 & 7 alone) | |
25 | ||
26 | #define NOP "nop\n\t" | |
27 | /* | |
28 | Each 'nop' statement executes in one machine cycle (at 16 MHz) yielding a 62.5 ns (nanosecond) delay. | |
29 | __asm__("nop\n\t"); | |
30 | __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");// Synatax for multiple Delays | |
31 | */ | |
32 | ||
33 | /* | |
34 | Create an array of values [xx] by [nn] to control each LED NODE in the standard RadioShack strip. | |
35 | [xx] is the number of FRAMES in your sequence and [nn] is the number of NODES for YOUR LED strip, usually 10. | |
36 | ||
37 | PROGMEM stores the data in the AVR chip's PROGRAM memory. This has much more space than the 2K of variable RAM memory. | |
38 | The two dimensional array has one value for each one of the 10 TM1803 RGB LEDs - controlling the color. | |
39 | Each "row" can change the colors assigned. This is like a FRAME in an animation. Changing the FRAME's | |
40 | values and patterns can create the animation effect of motion. | |
41 | ||
42 | We will then read out these values one FRAME (row) at a time to create the 24bit serial pulse train that is OUTPUT to the LED Strip. | |
43 | ||
44 | Each ROW is sent as OUTPUT and it will SET the COLOR for each of the TEN (10) nodes. | |
45 | Each ROW is a NEW FRAME, changing the colors again and again, creating a pattern. | |
46 | ||
47 | The order of the HEX doublets (bytes) controlling the COLORS is: Green - Blue - Red. | |
48 | ff is full brightness - so 0xff0000 is full GREEN, 0xx00ff00 is full BLUE, 0x0000ff is full RED | |
49 | */ | |
50 | ||
51 | // In the Radio Shack RGB Strip, the TM1803 controls RED with the last HEX byte | |
52 | PROGMEM const unsigned long chasing_red[][10]={ | |
53 | {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
54 | {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
55 | {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
56 | {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
57 | {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
58 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000}, | |
59 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000}, | |
60 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000}, | |
61 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000}, | |
62 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0}, | |
63 | }; | |
64 | ||
65 | PROGMEM const unsigned long first_red[][10]={ | |
66 | {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
67 | {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
68 | {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
69 | {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
70 | {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
71 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000}, | |
72 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000}, | |
73 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000}, | |
74 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000}, | |
75 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0}, | |
76 | }; | |
77 | ||
78 | PROGMEM const unsigned long second_red[][10]={ | |
79 | {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0}, | |
80 | {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0}, | |
81 | {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0}, | |
82 | {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0}, | |
83 | {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x0000f0}, | |
84 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x0000f0}, | |
85 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x0000f0}, | |
86 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x0000f0}, | |
87 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0}, | |
88 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0}, | |
89 | }; | |
90 | ||
91 | PROGMEM const unsigned long first_white[][10]={ | |
92 | {0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0}, | |
93 | {0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0}, | |
94 | {0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0}, | |
95 | {0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0}, | |
96 | {0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x0000f0,0x0000f0}, | |
97 | {0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x0000f0,0x0000f0}, | |
98 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x0000f0,0x0000f0}, | |
99 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0}, | |
100 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0}, | |
101 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0}, | |
102 | }; | |
103 | ||
104 | PROGMEM const unsigned long second_white[][10]={ | |
105 | {0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0}, | |
106 | {0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0}, | |
107 | {0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0}, | |
108 | {0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0}, | |
109 | {0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0}, | |
110 | {0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0xd0d0d0,0x0000f0,0x0000f0}, | |
111 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
112 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
113 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
114 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
115 | }; | |
116 | ||
117 | PROGMEM const unsigned long first_blue[][10]={ | |
118 | {0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
119 | {0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
120 | {0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
121 | {0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
122 | {0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
123 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
124 | {0x00f000,0x000000,0x000000,0x000000,0x000000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
125 | {0x000000,0x00f000,0x000000,0x000000,0x000000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
126 | {0x000000,0x000000,0x00f000,0x000000,0x000000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
127 | {0x000000,0x000000,0x000000,0x00f000,0x000000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
128 | }; | |
129 | ||
130 | PROGMEM const unsigned long second_blue[][10]={ | |
131 | {0x000000,0x000000,0x000000,0x000000,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
132 | {0x0000f0,0x000000,0x000000,0x000000,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
133 | {0x000000,0x0000f0,0x000000,0x000000,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
134 | {0x000000,0x000000,0x0000f0,0x000000,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
135 | {0x000000,0x000000,0x000000,0x0000f0,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
136 | {0x0000f0,0x000000,0x000000,0x0000f0,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
137 | {0x000000,0x0000f0,0x000000,0x0000f0,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
138 | {0x000000,0x000000,0x0000f0,0x0000f0,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
139 | {0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0}, | |
140 | }; | |
141 | ||
142 | // In the Radio Shack RGB Strip, the TM1803 controls GREEN with the 1st, BLUE with the 2nd, and RED with the last HEX byte, | |
143 | PROGMEM const unsigned long red_white_blue[][10]={ | |
144 | {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
145 | {0xd0d0d0,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
146 | {0x00f000,0xd0d0d0,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
147 | {0x000000,0x00f000,0xd0d0d0,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
148 | {0x000000,0x000000,0x00f000,0xd0d0d0,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
149 | {0x000000,0x000000,0x000000,0x00f000,0xd0d0d0,0x0000f0,0x000000,0x000000,0x000000,0x000000}, | |
150 | {0x000000,0x000000,0x000000,0x000000,0x00f000,0xd0d0d0,0x0000f0,0x000000,0x000000,0x000000}, | |
151 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0xd0d0d0,0x0000f0,0x000000,0x000000}, | |
152 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0xd0d0d0,0x0000f0,0x000000}, | |
153 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0xd0d0d0,0x0000f0}, | |
154 | }; | |
155 | ||
156 | ||
157 | // WHITE is ALL HEX bytes (can vary the "color" of white by changing these | |
158 | PROGMEM const unsigned long chasing_white[][10]={ | |
159 | {0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
160 | {0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
161 | {0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
162 | {0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
163 | {0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
164 | {0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000}, | |
165 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000}, | |
166 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000}, | |
167 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000}, | |
168 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd}, | |
169 | }; | |
170 | ||
171 | // BLUE is the second HEX byte | |
172 | PROGMEM const unsigned long chasing_blue[][10]={ | |
173 | {0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
174 | {0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
175 | {0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
176 | {0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
177 | {0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
178 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000}, | |
179 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000}, | |
180 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000}, | |
181 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000}, | |
182 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000}, | |
183 | }; | |
184 | ||
185 | // GREEN is the first HEX byte | |
186 | PROGMEM const unsigned long chasing_green[][10]={ | |
187 | {0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
188 | {0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
189 | {0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
190 | {0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
191 | {0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
192 | {0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000}, | |
193 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000}, | |
194 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000}, | |
195 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000}, | |
196 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000}, | |
197 | }; | |
198 | ||
199 | // Each ROW changes which LED is bright, creating a moving pattern | |
200 | PROGMEM const unsigned long pattern_test_comet1[][10]={ | |
201 | {0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
202 | {0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
203 | {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
204 | {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
205 | {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
206 | {0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000}, | |
207 | {0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000}, | |
208 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000}, | |
209 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000}, | |
210 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd}, | |
211 | }; | |
212 | ||
213 | PROGMEM const unsigned long pattern_test_comet2[][10]={ | |
214 | {0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000}, | |
215 | {0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000}, | |
216 | {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000}, | |
217 | {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000}, | |
218 | {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd}, | |
219 | {0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000}, | |
220 | {0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000}, | |
221 | {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000}, | |
222 | {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000}, | |
223 | {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd}, | |
224 | }; | |
225 | ||
226 | PROGMEM const unsigned long pattern_test_comet3[][10]={ | |
227 | {0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd}, | |
228 | {0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x444444}, | |
229 | {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x444444,0x111111}, | |
230 | {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0xfdfdfd,0x444444,0x111111,0x000000}, | |
231 | {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0xfdfdfd,0x444444,0x111111,0x000000,0x000000}, | |
232 | {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0xfdfdfd,0x444444,0x111111,0x000000,0x000000}, | |
233 | {0x000000,0x000000,0x000000,0xfdfdfd,0x444444,0x444444,0xfdfdfd,0x000000,0x000000,0x000000}, | |
234 | {0x000000,0x000000,0xfdfdfd,0x444444,0x111111,0x111111,0x444444,0xfdfdfd,0x000000,0x000000}, | |
235 | {0x000000,0xfdfdfd,0x444444,0x111111,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000}, | |
236 | {0xfdfdfd,0x444444,0x111111,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd}, | |
237 | }; | |
238 | ||
239 | // Each row changes the color and intensity of the LEDs | |
240 | PROGMEM const unsigned long rainbow1[][10]={ | |
241 | {0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000}, | |
242 | {0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000}, | |
243 | {0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000}, | |
244 | {0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd}, | |
245 | {0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd}, | |
246 | {0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd}, | |
247 | {0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00}, | |
248 | {0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00}, | |
249 | {0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00}, | |
250 | {0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x0000fd,0x00fd00,0xfdfd00,0xfdfd00}, | |
251 | }; | |
252 | ||
253 | PROGMEM const unsigned long cylon_test_red[][10]={ | |
254 | {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
255 | {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000}, | |
256 | {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000}, | |
257 | {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000}, | |
258 | {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000}, | |
259 | {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000}, | |
260 | {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000}, | |
261 | {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000}, | |
262 | {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x0000f0,0x000000,0x000000}, | |
263 | {0x000000,0x000000,0x000000,0x000000,0xf0f0f0,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
264 | }; | |
265 | ||
266 | PROGMEM const unsigned long red_cylon_R[][10]={ | |
267 | {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
268 | {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
269 | {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
270 | {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
271 | {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
272 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000}, | |
273 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000}, | |
274 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000}, | |
275 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000}, | |
276 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0}, | |
277 | }; | |
278 | ||
279 | PROGMEM const unsigned long red_cylon_L[][10]={ | |
280 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0}, | |
281 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000}, | |
282 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000}, | |
283 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000}, | |
284 | {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000}, | |
285 | {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
286 | {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
287 | {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
288 | {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
289 | {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, | |
290 | }; | |
291 | ||
292 | PROGMEM const unsigned long star_trek_bridge[][10]={ | |
293 | {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0}, | |
294 | {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000}, | |
295 | {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000}, | |
296 | {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000}, | |
297 | {0x000000,0x000000,0x000000,0x000000,0x0000f0,0xf000f0,0x000000,0x000000,0x000000,0x000000}, | |
298 | {0x000000,0x000000,0x000000,0x000000,0xd000d0,0xd000d0,0x000000,0x000000,0x000000,0x000000}, | |
299 | {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000}, | |
300 | {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000}, | |
301 | {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000}, | |
302 | {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0}, | |
303 | }; | |
304 | ||
305 | // *********************************************************************************************************** | |
306 | // * INITIALIZE the system on Power Up or after a RESET | |
307 | // * | |
308 | // *********************************************************************************************************** | |
309 | void setup() { | |
310 | ||
311 | STRIP_PINOUT; // sets the output pin to control the LED Strip | |
312 | reset_strip(); // resets each of the LED nodes to OFF | |
313 | ||
314 | } | |
315 | ||
316 | ||
317 | // *********************************************************************************************************** | |
318 | // * Main Program Loop | |
319 | // * | |
320 | // *********************************************************************************************************** | |
321 | void loop() | |
322 | { | |
323 | ||
324 | /* | |
325 | This is a TEST PATTERN to show that all of the | |
326 | segments ("nodes") are working properly. | |
327 | This Runs Only ONCE ... because the next loop | |
328 | never finishes. | |
329 | ||
330 | You could remove the WHILE loop and then these patterns | |
331 | would run continuously, as long as there is power to the board. | |
332 | */ | |
333 | ||
334 | /* CHASING PRIMARY COLORS */ | |
335 | int q = 1; | |
336 | send_1M_pattern(chasing_green, 10, 50); | |
337 | delay(500); | |
338 | send_1M_pattern(chasing_blue, 10, 500); | |
339 | delay(500); | |
340 | send_1M_pattern(chasing_red, 10, 500); | |
341 | delay(500); | |
342 | ||
343 | /* CHASING WHITE */ | |
344 | send_1M_pattern(chasing_white, 10, 500); | |
345 | delay(500); | |
346 | ||
347 | send_1M_pattern(pattern_test_comet1, 10, 70); | |
348 | delay(500); | |
349 | send_1M_pattern(pattern_test_comet2, 10, 70); | |
350 | delay(500); | |
351 | send_1M_pattern(pattern_test_comet3, 10, 70); | |
352 | delay(500); | |
353 | ||
354 | /* RAINBOW TEST PATTERN */ | |
355 | send_1M_pattern(rainbow1, 10, 100); | |
356 | delay(1000); // Wait for one second to make you think about the infinite loop | |
357 | ||
358 | ||
359 | /* TEN CYCLES OF TREK BRIDGE */ | |
360 | q = 10; | |
361 | while (q>0){ | |
362 | send_1M_pattern(star_trek_bridge, 10, 50); | |
363 | q -= 1; | |
364 | } | |
365 | delay(500); | |
366 | ||
367 | /* | |
368 | Use this to control which pattern is sent to the | |
369 | LED Strip. | |
370 | ||
371 | This loop runs will run continuously inside the "master" loop; | |
372 | because the value of WHILE (1) never changes. You may elminate this, | |
373 | or add your own control program. | |
374 | */ | |
375 | while (1) | |
376 | { | |
377 | send_1M_pattern(chasing_white, 10, 100); | |
378 | delay(500); | |
379 | send_1M_pattern(rainbow1, 10, 100); | |
380 | delay(500); | |
381 | send_1M_pattern(chasing_green, 10, 50); | |
382 | delay(1000); // Wait for one second to make you think about the infinite loop | |
383 | ||
384 | /* RAINBOW TEST PATTERN */ | |
385 | send_1M_pattern(rainbow1, 10, 100); | |
386 | delay(1000); // Wait for one second to make you think about the infinite loop | |
387 | ||
388 | /* TEN CYCLES OF CYLON */ | |
389 | q = 10; | |
390 | while (q>0){ | |
391 | send_1M_pattern(cylon_test_red, 10, 100); | |
392 | delay(500); | |
393 | send_1M_pattern(red_cylon_R, 10, 70); | |
394 | send_1M_pattern(red_cylon_L, 10, 70); | |
395 | q -= 1; | |
396 | } | |
397 | delay(500); | |
398 | ||
399 | ||
400 | /* 5 CYCLES OF SIMPLE RED-WHITE-BLUE */ | |
401 | q = 5; | |
402 | while (q>0){ | |
403 | send_1M_pattern(chasing_red, 10, 100); | |
404 | delay(500); | |
405 | send_1M_pattern(chasing_white, 10, 100); | |
406 | delay(500); | |
407 | send_1M_pattern(chasing_blue, 10, 100); | |
408 | delay(500); | |
409 | q -= 1; | |
410 | } | |
411 | delay(500); | |
412 | ||
413 | /* FIVE CYCLES OF TREK BRIDGE */ | |
414 | q = 5; | |
415 | while (q>0){ | |
416 | send_1M_pattern(star_trek_bridge, 10, 60); | |
417 | q -= 1; | |
418 | } | |
419 | delay(500); | |
420 | ||
421 | /* 10 CYCLES CHASING RED-WHITE-BLUE */ | |
422 | q = 10; | |
423 | while (q>0){ | |
424 | send_1M_pattern(red_white_blue, 10, 100); | |
425 | delay(300); | |
426 | q -= 1; | |
427 | } | |
428 | delay(500); | |
429 | ||
430 | /* 10 CYCLES OF RED-WHITE-BLUE BUILD UP */ | |
431 | q = 10; | |
432 | while (q>0){ | |
433 | send_1M_pattern(first_red, 10, 100); | |
434 | delay(500); | |
435 | send_1M_pattern(second_red, 10, 100); | |
436 | delay(500); | |
437 | send_1M_pattern(first_white, 10, 100); | |
438 | delay(500); | |
439 | send_1M_pattern(second_white, 10, 100); | |
440 | delay(500); | |
441 | send_1M_pattern(first_blue, 10, 100); | |
442 | delay(250); | |
443 | send_1M_pattern(second_blue, 10, 100); | |
444 | delay(500); | |
445 | q -= 1; | |
446 | } | |
447 | delay(500); | |
448 | ||
449 | /* 10 CYCLES CHASING RED-WHITE-BLUE */ | |
450 | q = 10; | |
451 | while (q>0){ | |
452 | send_1M_pattern(red_white_blue, 10, 100); | |
453 | delay(300); | |
454 | q -= 1; | |
455 | } | |
456 | delay(500); | |
457 | ||
458 | } // END OF WHILE (1); | |
459 | ||
460 | ||
461 | } // END OF VOID LOOP() - In standard C++ otherwise known as MAIN(); | |
462 | ||
463 | /******************************************************************************* | |
464 | * Function Name: send_1M_pattern | |
465 | * Description: Transmit pattern to whole 1 meter strip | |
466 | * Input : Pointer to RAM pattern; pattern length; frame rate | |
467 | * Output: Sends out a serial pulse train using the send_strip function | |
468 | * Return: None | |
469 | *******************************************************************************/ | |
470 | void send_1M_pattern(const unsigned long data[][10], int pattern_no, int frame_rate) | |
471 | { | |
472 | int i=0; | |
473 | int j=0; | |
474 | uint32_t temp_data; | |
475 | ||
476 | // data[][10] is the name of the ARRAY with the RGB LED pattern values | |
477 | // Each pattern sends out [x] packets - one for each NODE (RGB LED cluster) in the strip | |
478 | // pattern_no is the [y] dimension of the array - the number of ROWS in each pattern array series | |
479 | // frame_rate is the DELAY before transmitting the next ROW in the pattern array | |
480 | for (i=0;i<pattern_no;i++) | |
481 | { | |
482 | noInterrupts(); // Turn OFF Interupts for more precise Pulse Timing using MCU processing cycles | |
483 | for (j=0;j<10;j++) | |
484 | { | |
485 | temp_data=pgm_read_dword_near(&data[i][j]); | |
486 | send_strip(temp_data); | |
487 | } | |
488 | interrupts(); // Turn ON Interrupts after data is sent | |
489 | ||
490 | delay(frame_rate); // Delay between each pulse train - sets the duration of each FRAME, before the next series is sent; | |
491 | /* CONTROLS THE VISUAL SPEED OF THE DISPLAY CHANGES */ | |
492 | ||
493 | } | |
494 | ||
495 | } | |
496 | ||
497 | ||
498 | /******************************************************************************* | |
499 | * Function Name: send_strip | |
500 | * Description: Creates and Transmits a serial train of 24 pulses for the LED strip | |
501 | * Input: 24-bit data sets intensity of each color, which will persist until | |
502 | * the next cycle makes a change | |
503 | * Output: Sends a train of 24 pulses (bits) representing values of 0 or 1 to the output pin () | |
504 | * TIMING the OUTPUT pulses using the duration of the MCU NOP @ 16MHz | |
505 | * Return: Nothing returned from function | |
506 | *******************************************************************************/ | |
507 | void send_strip(uint32_t data) | |
508 | { | |
509 | int i; | |
510 | unsigned long j=0x800000; | |
511 | ||
512 | int d; | |
513 | for (i=0;i<24;i++) | |
514 | { | |
515 | if (data & j) | |
516 | { | |
517 | DATA_1; | |
518 | // TM1803 BIT 1 - Set OUTPUT PIN HIGH & HOLD FOR 1.55us or ~ 26 MCU CYCLES = 1.625us; | |
519 | // The comparison (d<NN) uses ONE cycle, so the total delay is 2 X d X NOP (62.5 Nanoseconds); | |
520 | for (d=1;d<13;d++) | |
521 | { | |
522 | __asm__(NOP); | |
523 | } | |
524 | DATA_0; // Set OUTPUT PIN LOW ; | |
525 | } | |
526 | else | |
527 | { | |
528 | DATA_1; | |
529 | // TM1803 BIT 0 - Set OUTPUT PIN HIGH & HOLD FOR 0.78us or ~ 12 MCU CYCLES = .750us; | |
530 | // The comparison (d<NN) uses ONE cycle, so the total delay is 2 X d X NOP (62.5 Nanoseconds); | |
531 | for (d=1;d<5;d++) | |
532 | { | |
533 | __asm__(NOP); | |
534 | } | |
535 | DATA_0; // Set OUTPUT PIN LOW ; | |
536 | /*----------------------------*/ | |
537 | __asm__(NOP); | |
538 | __asm__(NOP); | |
539 | __asm__(NOP); | |
540 | /*----------------------------*/ | |
541 | } | |
542 | j>>=1; | |
543 | } | |
544 | ||
545 | } | |
546 | // END of send_strip(); | |
547 | ||
548 | /******************************************************************************* | |
549 | * Function Name: reset_strip | |
550 | * Description: Send a 0 pulse to reset all colors on all NODES of the strip | |
551 | * Input: None | |
552 | * Output: Sends out a looong duration 0 on the OUTPUT PIN to RESET the TM1803 chips | |
553 | * Return: None | |
554 | *******************************************************************************/ | |
555 | void reset_strip() | |
556 | { | |
557 | DATA_0; | |
558 | delayMicroseconds(20); // TM1803 specifies >= 24uS; // Arduino delay is actually slightly longer than assembler execution | |
559 | } |