Shiftbrite sequencer demo program. Controls a chain of 35 shiftbrites

Dependencies:   mbed

Committer:
4180_1
Date:
Thu Apr 21 15:03:38 2011 +0000
Revision:
0:fc0ddaee005d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:fc0ddaee005d 1 #include "mbed.h"
4180_1 0:fc0ddaee005d 2 // Shiftbrite Sequencer Demo Program
4180_1 0:fc0ddaee005d 3 //
4180_1 0:fc0ddaee005d 4 //Bits for Shiftbrite latch and enable pins
4180_1 0:fc0ddaee005d 5 DigitalOut latch(p15);
4180_1 0:fc0ddaee005d 6 DigitalOut enable(p16);
4180_1 0:fc0ddaee005d 7 //DigitalOut myled(LED1);
4180_1 0:fc0ddaee005d 8
4180_1 0:fc0ddaee005d 9 // SPI connections for LED chain
4180_1 0:fc0ddaee005d 10 SPI spi(p11, p12, p13);
4180_1 0:fc0ddaee005d 11
4180_1 0:fc0ddaee005d 12 //Serial PC(USBTX, USBRX);
4180_1 0:fc0ddaee005d 13
4180_1 0:fc0ddaee005d 14 Timer time_counter;
4180_1 0:fc0ddaee005d 15
4180_1 0:fc0ddaee005d 16 // number of LEDS in chain
4180_1 0:fc0ddaee005d 17 #define num_LEDS 35
4180_1 0:fc0ddaee005d 18
4180_1 0:fc0ddaee005d 19 // number of color values to sequence through
4180_1 0:fc0ddaee005d 20 #define Sequence_Length 17
4180_1 0:fc0ddaee005d 21
4180_1 0:fc0ddaee005d 22 // number of steps in fade effect
4180_1 0:fc0ddaee005d 23 #define Fade_Steps 64
4180_1 0:fc0ddaee005d 24
4180_1 0:fc0ddaee005d 25
4180_1 0:fc0ddaee005d 26 // Each LED'S RGB color values for each step in sequence is stored in an array
4180_1 0:fc0ddaee005d 27 int LED_Color [Sequence_Length][num_LEDS][3] = {0};
4180_1 0:fc0ddaee005d 28
4180_1 0:fc0ddaee005d 29 // delay times in seconds for each RGB color value in sequence
4180_1 0:fc0ddaee005d 30 // can be different for each sequence step
4180_1 0:fc0ddaee005d 31 float Sequence_Delay[Sequence_Length];
4180_1 0:fc0ddaee005d 32 int Sequence_Effect[Sequence_Length] = {0};
4180_1 0:fc0ddaee005d 33
4180_1 0:fc0ddaee005d 34
4180_1 0:fc0ddaee005d 35 // Write (Shift out) 10-bit RGB values to a single LED
4180_1 0:fc0ddaee005d 36 void Write_LED(int red, int green, int blue) {
4180_1 0:fc0ddaee005d 37 unsigned int low_color=0;
4180_1 0:fc0ddaee005d 38 unsigned int high_color=0;
4180_1 0:fc0ddaee005d 39 red=red;
4180_1 0:fc0ddaee005d 40 green=green;
4180_1 0:fc0ddaee005d 41 blue=blue;
4180_1 0:fc0ddaee005d 42 high_color=(blue<<4)|((red&0x3C0)>>6);
4180_1 0:fc0ddaee005d 43 low_color=(((red&0x3F)<<10)|(green));
4180_1 0:fc0ddaee005d 44 spi.write(high_color);
4180_1 0:fc0ddaee005d 45 spi.write(low_color);
4180_1 0:fc0ddaee005d 46 }
4180_1 0:fc0ddaee005d 47 // Sends Initial Current limits to all LEDs in array
4180_1 0:fc0ddaee005d 48 // used to correct for different RGB brightness levels in LEDs
4180_1 0:fc0ddaee005d 49 void Write_Init_Command(int red_level, int green_level, int blue_level) {
4180_1 0:fc0ddaee005d 50 unsigned int Init_Command = 0x40000000;
4180_1 0:fc0ddaee005d 51 int i=0;
4180_1 0:fc0ddaee005d 52 Init_Command = 0x40000000|(blue_level<<20)|(red_level<<10)|green_level;
4180_1 0:fc0ddaee005d 53 for (i=0; i<num_LEDS; i++) {
4180_1 0:fc0ddaee005d 54 spi.write(Init_Command>>16&0xFFFF);
4180_1 0:fc0ddaee005d 55 spi.write(Init_Command&0xFFFF);
4180_1 0:fc0ddaee005d 56 }
4180_1 0:fc0ddaee005d 57 wait(.000015);
4180_1 0:fc0ddaee005d 58 latch=1;
4180_1 0:fc0ddaee005d 59 wait(.000015);
4180_1 0:fc0ddaee005d 60 latch=0;
4180_1 0:fc0ddaee005d 61 }
4180_1 0:fc0ddaee005d 62
4180_1 0:fc0ddaee005d 63 // Sets all LEDs in a sequence step to a default background color
4180_1 0:fc0ddaee005d 64 void Set_Background_Color(int Seq_Step, int red, int green, int blue) {
4180_1 0:fc0ddaee005d 65 int i=0;
4180_1 0:fc0ddaee005d 66 for (i=0; i<num_LEDS; i++) {
4180_1 0:fc0ddaee005d 67 LED_Color[Seq_Step][i][0] = red;
4180_1 0:fc0ddaee005d 68 LED_Color[Seq_Step][i][1] = green;
4180_1 0:fc0ddaee005d 69 LED_Color[Seq_Step][i][2] = blue;
4180_1 0:fc0ddaee005d 70 }
4180_1 0:fc0ddaee005d 71 }
4180_1 0:fc0ddaee005d 72
4180_1 0:fc0ddaee005d 73 // Set a single LED in a Sequence Step to a color
4180_1 0:fc0ddaee005d 74 // Last LED in chain is LED #0
4180_1 0:fc0ddaee005d 75 //
4180_1 0:fc0ddaee005d 76 // LED address in 5x7 array
4180_1 0:fc0ddaee005d 77 // 35 in chain serpantine style
4180_1 0:fc0ddaee005d 78 // 34 33 32 31 30 29 28
4180_1 0:fc0ddaee005d 79 // 27 26 25 24 23 22 21
4180_1 0:fc0ddaee005d 80 // 20 19 18 17 16 15 14
4180_1 0:fc0ddaee005d 81 // 13 12 11 10 09 08 07
4180_1 0:fc0ddaee005d 82 // 06 05 04 03 02 01 00
4180_1 0:fc0ddaee005d 83 void Set_LED_Color(int Seq_Step, int LED_num, int red, int green, int blue) {
4180_1 0:fc0ddaee005d 84 LED_Color[Seq_Step][LED_num][0] = red;
4180_1 0:fc0ddaee005d 85 LED_Color[Seq_Step][LED_num][1] = green;
4180_1 0:fc0ddaee005d 86 LED_Color[Seq_Step][LED_num][2] = blue;
4180_1 0:fc0ddaee005d 87 }
4180_1 0:fc0ddaee005d 88
4180_1 0:fc0ddaee005d 89 int main() {
4180_1 0:fc0ddaee005d 90 int i=0;
4180_1 0:fc0ddaee005d 91 int j=0;
4180_1 0:fc0ddaee005d 92 int k=0;
4180_1 0:fc0ddaee005d 93 int red, green, blue;
4180_1 0:fc0ddaee005d 94 bool odd=false;
4180_1 0:fc0ddaee005d 95 spi.format(16,0);
4180_1 0:fc0ddaee005d 96 spi.frequency(500000);
4180_1 0:fc0ddaee005d 97 enable=0;
4180_1 0:fc0ddaee005d 98 latch=0;
4180_1 0:fc0ddaee005d 99 int flicker = 0;
4180_1 0:fc0ddaee005d 100 // Set currents using Allegro A6281's command mode
4180_1 0:fc0ddaee005d 101 Write_Init_Command(120, 100, 100);
4180_1 0:fc0ddaee005d 102 // Do once during initialization
4180_1 0:fc0ddaee005d 103 // OK at power on, but a reset could set it to an invalid mode
4180_1 0:fc0ddaee005d 104 //
4180_1 0:fc0ddaee005d 105 // See page 7 in A6281 datasheet
4180_1 0:fc0ddaee005d 106 // This feature can be used to adjust for different LED
4180_1 0:fc0ddaee005d 107 // brightness levels - values suggested from Macetech doc
4180_1 0:fc0ddaee005d 108
4180_1 0:fc0ddaee005d 109 // Clear out initial sequence values
4180_1 0:fc0ddaee005d 110 for (i=0; i<Sequence_Length; i++) {
4180_1 0:fc0ddaee005d 111 for (j=0; j<num_LEDS; j++) {
4180_1 0:fc0ddaee005d 112 for (k=0; k<4; k++) {
4180_1 0:fc0ddaee005d 113 LED_Color[i][j][k]=0;
4180_1 0:fc0ddaee005d 114 }
4180_1 0:fc0ddaee005d 115 }
4180_1 0:fc0ddaee005d 116 Sequence_Delay[i]=0;
4180_1 0:fc0ddaee005d 117 Sequence_Effect[i]=0;
4180_1 0:fc0ddaee005d 118 }
4180_1 0:fc0ddaee005d 119 // Color data values for LEDs to sequence through
4180_1 0:fc0ddaee005d 120 // Sequence step 0
4180_1 0:fc0ddaee005d 121 Set_Background_Color(0, 1023, 0, 0); //LEDs RED
4180_1 0:fc0ddaee005d 122 Sequence_Delay[0] = 1;
4180_1 0:fc0ddaee005d 123 Sequence_Effect[0] = 0;
4180_1 0:fc0ddaee005d 124 // Sequence step 1
4180_1 0:fc0ddaee005d 125 LED_Color[1][0][0] = 0;
4180_1 0:fc0ddaee005d 126 Set_Background_Color(1, 0, 1023, 0); //LEDs GREEN
4180_1 0:fc0ddaee005d 127 Sequence_Delay[1] = 2;
4180_1 0:fc0ddaee005d 128 Sequence_Effect[1] = 1; //Fade from RED to GREEN Effect
4180_1 0:fc0ddaee005d 129 // Sequence step 2
4180_1 0:fc0ddaee005d 130 Set_Background_Color(2, 0, 0, 1023); //LEDs BLUE
4180_1 0:fc0ddaee005d 131 Sequence_Delay[2] = 2;
4180_1 0:fc0ddaee005d 132 Sequence_Effect[2] = 1; //Fade from GREEN to BLUE Effect
4180_1 0:fc0ddaee005d 133 // Sequence step 3
4180_1 0:fc0ddaee005d 134 Set_Background_Color(3, 0, 0, 1023);
4180_1 0:fc0ddaee005d 135 Sequence_Delay[3] = 1; //Stay at this value for 1 seconds
4180_1 0:fc0ddaee005d 136 Sequence_Effect[3] = 0;
4180_1 0:fc0ddaee005d 137 // Sequence step 4
4180_1 0:fc0ddaee005d 138 Set_Background_Color(4,1023,200,0); //LEDs all ORANGE
4180_1 0:fc0ddaee005d 139 Sequence_Delay[4] = 5;
4180_1 0:fc0ddaee005d 140 Sequence_Effect[4] = 2; //Flicker or Twinkle Effect
4180_1 0:fc0ddaee005d 141 // Sequence step 5
4180_1 0:fc0ddaee005d 142 Set_Background_Color(5,1023,1023,0); //LEDs all YELLOW
4180_1 0:fc0ddaee005d 143 Sequence_Delay[5] = 5;
4180_1 0:fc0ddaee005d 144 Sequence_Effect[5] = 3; //Flashing Marquee Sign Effect
4180_1 0:fc0ddaee005d 145 // Sequence step 6
4180_1 0:fc0ddaee005d 146 LED_Color[6][0][0] = 1023; //LED 0 RED
4180_1 0:fc0ddaee005d 147 LED_Color[6][0][1] = 0;
4180_1 0:fc0ddaee005d 148 LED_Color[6][0][2] = 0;
4180_1 0:fc0ddaee005d 149 LED_Color[6][1][0] = 1023;
4180_1 0:fc0ddaee005d 150 LED_Color[6][1][1] = 1023;
4180_1 0:fc0ddaee005d 151 LED_Color[6][1][2] = 1023; //LED 1 WHITE
4180_1 0:fc0ddaee005d 152 LED_Color[6][2][0] = 0;
4180_1 0:fc0ddaee005d 153 LED_Color[6][2][1] = 0;
4180_1 0:fc0ddaee005d 154 LED_Color[6][2][2] = 1023; //LED 1 BLUE
4180_1 0:fc0ddaee005d 155 Sequence_Delay[6] = 5;
4180_1 0:fc0ddaee005d 156 Sequence_Effect[6] = 4; //Shift Colors
4180_1 0:fc0ddaee005d 157 // Sequence step 7
4180_1 0:fc0ddaee005d 158 Set_Background_Color(7,1023,1023,1023); //LEDs all WHITE
4180_1 0:fc0ddaee005d 159 Sequence_Delay[7] = 1;
4180_1 0:fc0ddaee005d 160 Sequence_Effect[7] = 0;
4180_1 0:fc0ddaee005d 161 //Sequence step 8
4180_1 0:fc0ddaee005d 162 Set_Background_Color(8,0,0,0); //LEDs all Black
4180_1 0:fc0ddaee005d 163 Sequence_Delay[8] = 2;
4180_1 0:fc0ddaee005d 164 Sequence_Effect[8]= 1; //Fade to Black
4180_1 0:fc0ddaee005d 165 //Sequence step 9
4180_1 0:fc0ddaee005d 166 Set_Background_Color(9,0,0,0); //LEDs all Black
4180_1 0:fc0ddaee005d 167 Sequence_Delay[9] = 1.5;
4180_1 0:fc0ddaee005d 168 Sequence_Effect[9]= 0;
4180_1 0:fc0ddaee005d 169 //Sequence step 10
4180_1 0:fc0ddaee005d 170 Sequence_Delay[10] = 6;
4180_1 0:fc0ddaee005d 171 Sequence_Effect[10]= 5; //Random Bright Colors
4180_1 0:fc0ddaee005d 172 //Sequence step 11
4180_1 0:fc0ddaee005d 173 Set_Background_Color(11,100,100,100); //LEDs all dim WHITE
4180_1 0:fc0ddaee005d 174 Set_LED_Color(11,34,0,0,1023); //char M
4180_1 0:fc0ddaee005d 175 Set_LED_Color(11,33,0,0,1023);
4180_1 0:fc0ddaee005d 176 Set_LED_Color(11,32,0,0,1023);
4180_1 0:fc0ddaee005d 177 Set_LED_Color(11,31,0,0,1023);
4180_1 0:fc0ddaee005d 178 Set_LED_Color(11,30,0,0,1023);
4180_1 0:fc0ddaee005d 179 Set_LED_Color(11,29,0,0,1023);
4180_1 0:fc0ddaee005d 180 Set_LED_Color(11,28,0,0,1023);
4180_1 0:fc0ddaee005d 181 Set_LED_Color(11,22,0,0,1023);
4180_1 0:fc0ddaee005d 182 Set_LED_Color(11,16,0,0,1023);
4180_1 0:fc0ddaee005d 183 Set_LED_Color(11,17,0,0,1023);
4180_1 0:fc0ddaee005d 184 Set_LED_Color(11,8,0,0,1023);
4180_1 0:fc0ddaee005d 185 Set_LED_Color(11,0,0,0,1023);
4180_1 0:fc0ddaee005d 186 Set_LED_Color(11,1,0,0,1023);
4180_1 0:fc0ddaee005d 187 Set_LED_Color(11,2,0,0,1023);
4180_1 0:fc0ddaee005d 188 Set_LED_Color(11,3,0,0,1023);
4180_1 0:fc0ddaee005d 189 Set_LED_Color(11,4,0,0,1023);
4180_1 0:fc0ddaee005d 190 Set_LED_Color(11,5,0,0,1023);
4180_1 0:fc0ddaee005d 191 Set_LED_Color(11,6,0,0,1023);
4180_1 0:fc0ddaee005d 192 Sequence_Effect[11] = 0;
4180_1 0:fc0ddaee005d 193 Sequence_Delay[11] = 3;
4180_1 0:fc0ddaee005d 194 //Sequence step 12
4180_1 0:fc0ddaee005d 195 Set_Background_Color(12,100,100,100); //LEDs all dim WHITE
4180_1 0:fc0ddaee005d 196 Set_LED_Color(12,34,0,0,1023); // char b
4180_1 0:fc0ddaee005d 197 Set_LED_Color(12,33,0,0,1023);
4180_1 0:fc0ddaee005d 198 Set_LED_Color(12,32,0,0,1023);
4180_1 0:fc0ddaee005d 199 Set_LED_Color(12,31,0,0,1023);
4180_1 0:fc0ddaee005d 200 Set_LED_Color(12,30,0,0,1023);
4180_1 0:fc0ddaee005d 201 Set_LED_Color(12,29,0,0,1023);
4180_1 0:fc0ddaee005d 202 Set_LED_Color(12,28,0,0,1023);
4180_1 0:fc0ddaee005d 203 Set_LED_Color(12,27,0,0,1023);
4180_1 0:fc0ddaee005d 204 Set_LED_Color(12,24,0,0,1023);
4180_1 0:fc0ddaee005d 205 Set_LED_Color(12,20,0,0,1023);
4180_1 0:fc0ddaee005d 206 Set_LED_Color(12,17,0,0,1023);
4180_1 0:fc0ddaee005d 207 Set_LED_Color(12,12,0,0,1023);
4180_1 0:fc0ddaee005d 208 Set_LED_Color(12,11,0,0,1023);
4180_1 0:fc0ddaee005d 209 Sequence_Effect[12] = 0;
4180_1 0:fc0ddaee005d 210 Sequence_Delay[12] = 3;
4180_1 0:fc0ddaee005d 211 //Sequence step 13
4180_1 0:fc0ddaee005d 212 Set_Background_Color(13,100,100,100); //LEDs all dim WHITE
4180_1 0:fc0ddaee005d 213 Set_LED_Color(13,34,0,0,1023); //char E
4180_1 0:fc0ddaee005d 214 Set_LED_Color(13,33,0,0,1023);
4180_1 0:fc0ddaee005d 215 Set_LED_Color(13,32,0,0,1023);
4180_1 0:fc0ddaee005d 216 Set_LED_Color(13,31,0,0,1023);
4180_1 0:fc0ddaee005d 217 Set_LED_Color(13,30,0,0,1023);
4180_1 0:fc0ddaee005d 218 Set_LED_Color(13,29,0,0,1023);
4180_1 0:fc0ddaee005d 219 Set_LED_Color(13,28,0,0,1023);
4180_1 0:fc0ddaee005d 220 Set_LED_Color(13,27,0,0,1023);
4180_1 0:fc0ddaee005d 221 Set_LED_Color(13,24,0,0,1023);
4180_1 0:fc0ddaee005d 222 Set_LED_Color(13,21,0,0,1023);
4180_1 0:fc0ddaee005d 223 Set_LED_Color(13,20,0,0,1023);
4180_1 0:fc0ddaee005d 224 Set_LED_Color(13,17,0,0,1023);
4180_1 0:fc0ddaee005d 225 Set_LED_Color(13,14,0,0,1023);
4180_1 0:fc0ddaee005d 226 Set_LED_Color(13,13,0,0,1023);
4180_1 0:fc0ddaee005d 227 Set_LED_Color(13,7,0,0,1023);
4180_1 0:fc0ddaee005d 228 Set_LED_Color(13,6,0,0,1023);
4180_1 0:fc0ddaee005d 229 Set_LED_Color(13,0,0,0,1023);
4180_1 0:fc0ddaee005d 230 Sequence_Effect[13] = 0;
4180_1 0:fc0ddaee005d 231 Sequence_Delay[13] = 3;
4180_1 0:fc0ddaee005d 232 //Sequence step 14
4180_1 0:fc0ddaee005d 233 Set_Background_Color(14,100,100,100); //LEDs all dim WHITE
4180_1 0:fc0ddaee005d 234 Set_LED_Color(14,5,0,0,1023); //char d
4180_1 0:fc0ddaee005d 235 Set_LED_Color(14,4,0,0,1023);
4180_1 0:fc0ddaee005d 236 Set_LED_Color(14,3,0,0,1023);
4180_1 0:fc0ddaee005d 237 Set_LED_Color(14,6,0,0,1023);
4180_1 0:fc0ddaee005d 238 Set_LED_Color(14,2,0,0,1023);
4180_1 0:fc0ddaee005d 239 Set_LED_Color(14,1,0,0,1023);
4180_1 0:fc0ddaee005d 240 Set_LED_Color(14,0,0,0,1023);
4180_1 0:fc0ddaee005d 241 Set_LED_Color(14,13,0,0,1023);
4180_1 0:fc0ddaee005d 242 Set_LED_Color(14,10,0,0,1023);
4180_1 0:fc0ddaee005d 243 Set_LED_Color(14,20,0,0,1023);
4180_1 0:fc0ddaee005d 244 Set_LED_Color(14,17,0,0,1023);
4180_1 0:fc0ddaee005d 245 Set_LED_Color(14,26,0,0,1023);
4180_1 0:fc0ddaee005d 246 Set_LED_Color(14,25,0,0,1023);
4180_1 0:fc0ddaee005d 247 Sequence_Effect[14] = 0;
4180_1 0:fc0ddaee005d 248 Sequence_Delay[14] = 3;
4180_1 0:fc0ddaee005d 249 //Sequence step 15
4180_1 0:fc0ddaee005d 250 Set_Background_Color(15,0,0,0); //LEDs all Black
4180_1 0:fc0ddaee005d 251 Sequence_Delay[15] = 2;
4180_1 0:fc0ddaee005d 252 Sequence_Effect[15]= 1; //Fade to Black
4180_1 0:fc0ddaee005d 253 //Sequence step 16
4180_1 0:fc0ddaee005d 254 Set_Background_Color(16,0,0,0); //LEDs all Black
4180_1 0:fc0ddaee005d 255 Sequence_Delay[16] = 2;
4180_1 0:fc0ddaee005d 256 Sequence_Effect[16]= 0; //Black
4180_1 0:fc0ddaee005d 257 // add more steps or LEDs if needed and change #defines
4180_1 0:fc0ddaee005d 258
4180_1 0:fc0ddaee005d 259 wait(1);
4180_1 0:fc0ddaee005d 260 // Repeat Sequence Forever
4180_1 0:fc0ddaee005d 261 while (1) {
4180_1 0:fc0ddaee005d 262 Write_Init_Command(120, 100, 100);
4180_1 0:fc0ddaee005d 263 //Step through the Sequence Values
4180_1 0:fc0ddaee005d 264 for (j = 0; j < Sequence_Length; j++) {
4180_1 0:fc0ddaee005d 265 // myled= !myled;
4180_1 0:fc0ddaee005d 266 switch (Sequence_Effect[j]) {
4180_1 0:fc0ddaee005d 267 case 0: {
4180_1 0:fc0ddaee005d 268 // Step through each LED in chain at each sequence step
4180_1 0:fc0ddaee005d 269 for (i = 0; i < num_LEDS; i++) {
4180_1 0:fc0ddaee005d 270 //Writes 32-bits of RGB color data to LED using SPI hardware
4180_1 0:fc0ddaee005d 271 Write_LED( LED_Color[j][i][0], LED_Color[j][i][1], LED_Color[j][i][2]);
4180_1 0:fc0ddaee005d 272 // Uncomment to get status info on serial port
4180_1 0:fc0ddaee005d 273 // printf("i= %d, j= %d\n\r",i,j);
4180_1 0:fc0ddaee005d 274 // printf(" %d %d %d\n\r",LED_Color[j][i][0], LED_Color[j][i][1], LED_Color[j][i][2]);
4180_1 0:fc0ddaee005d 275 }
4180_1 0:fc0ddaee005d 276 //Load in new values just shifted out to LED chain by setting latch high
4180_1 0:fc0ddaee005d 277 wait(.000015);
4180_1 0:fc0ddaee005d 278 latch=1;
4180_1 0:fc0ddaee005d 279 wait(.000015);
4180_1 0:fc0ddaee005d 280 latch=0;
4180_1 0:fc0ddaee005d 281 //Delay for this step in the sequence
4180_1 0:fc0ddaee005d 282 wait(Sequence_Delay[j]);
4180_1 0:fc0ddaee005d 283 break;
4180_1 0:fc0ddaee005d 284 }
4180_1 0:fc0ddaee005d 285 case 1: {
4180_1 0:fc0ddaee005d 286 //Lighing Effect: Fade into new color from previous color (note: can't fade first sequence step!)
4180_1 0:fc0ddaee005d 287 for (k = 0; k<=Fade_Steps; k++) {
4180_1 0:fc0ddaee005d 288 // Step through each LED in chain at each fade sequence step
4180_1 0:fc0ddaee005d 289 for (i = 0; i < num_LEDS; i++) {
4180_1 0:fc0ddaee005d 290 red = LED_Color[j-1][i][0] + k*(LED_Color[j][i][0]-LED_Color[j-1][i][0])/Fade_Steps;
4180_1 0:fc0ddaee005d 291 green = LED_Color[j-1][i][1] + k*(LED_Color[j][i][1]-LED_Color[j-1][i][1])/Fade_Steps;
4180_1 0:fc0ddaee005d 292 blue = LED_Color[j-1][i][2] + k*(LED_Color[j][i][2]-LED_Color[j-1][i][2])/Fade_Steps;
4180_1 0:fc0ddaee005d 293 //Writes 32-bits of RGB color data to LED using SPI hardware
4180_1 0:fc0ddaee005d 294 Write_LED(red, green, blue);
4180_1 0:fc0ddaee005d 295 // Uncomment to get status info on serial port
4180_1 0:fc0ddaee005d 296 // printf("i= %d, j= %d\n\r",i,j);
4180_1 0:fc0ddaee005d 297 // printf(" %d %d %d\n\r",LED_Color[j][i][0], LED_Color[j][i][1], LED_Color[j][i][2]);
4180_1 0:fc0ddaee005d 298 }
4180_1 0:fc0ddaee005d 299 //Load in new values just shifted out to LED chain by setting latch high
4180_1 0:fc0ddaee005d 300 wait(.000015);
4180_1 0:fc0ddaee005d 301 latch=1;
4180_1 0:fc0ddaee005d 302 wait(.000015);
4180_1 0:fc0ddaee005d 303 latch=0;
4180_1 0:fc0ddaee005d 304 //Delay for this step in the fade sequence
4180_1 0:fc0ddaee005d 305 wait(Sequence_Delay[j]/Fade_Steps);
4180_1 0:fc0ddaee005d 306 }
4180_1 0:fc0ddaee005d 307 break;
4180_1 0:fc0ddaee005d 308 }
4180_1 0:fc0ddaee005d 309 case 2: {
4180_1 0:fc0ddaee005d 310 //Lighting Effect: Flicker or Twinkle somewhat like a flame
4180_1 0:fc0ddaee005d 311 time_counter.reset();
4180_1 0:fc0ddaee005d 312 time_counter.start();
4180_1 0:fc0ddaee005d 313 while (time_counter.read()<Sequence_Delay[j]) {
4180_1 0:fc0ddaee005d 314 for (i = 0; i < num_LEDS; i++) {
4180_1 0:fc0ddaee005d 315 flicker = rand();
4180_1 0:fc0ddaee005d 316 if (flicker>0x40000000)
4180_1 0:fc0ddaee005d 317 //Writes 32-bits of RGB color data to LED using SPI hardware
4180_1 0:fc0ddaee005d 318 Write_LED( LED_Color[j][i][0], LED_Color[j][i][1], LED_Color[j][i][2]);
4180_1 0:fc0ddaee005d 319 // Uncomment to get status info on serial port
4180_1 0:fc0ddaee005d 320 // printf("i= %d, j= %d\n\r",i,j);
4180_1 0:fc0ddaee005d 321 // printf(" %d %d %d\n\r",LED_Color[j][i][0], LED_Color[j][i][1], LED_Color[j][i][2]);
4180_1 0:fc0ddaee005d 322 else
4180_1 0:fc0ddaee005d 323 Write_LED( LED_Color[j][i][0]/2, LED_Color[j][i][1]/2, LED_Color[j][i][2]/2);
4180_1 0:fc0ddaee005d 324 }
4180_1 0:fc0ddaee005d 325 //Load in new values just shifted out to LED chain by setting latch high
4180_1 0:fc0ddaee005d 326 wait(.000015);
4180_1 0:fc0ddaee005d 327 latch=1;
4180_1 0:fc0ddaee005d 328 wait(.000015);
4180_1 0:fc0ddaee005d 329 latch=0;
4180_1 0:fc0ddaee005d 330 wait(.05);
4180_1 0:fc0ddaee005d 331 }
4180_1 0:fc0ddaee005d 332 time_counter.stop();
4180_1 0:fc0ddaee005d 333 break;
4180_1 0:fc0ddaee005d 334 }
4180_1 0:fc0ddaee005d 335 case 3: {
4180_1 0:fc0ddaee005d 336 //Lighting Effect: Flashing Broadway Marquee Sign Style
4180_1 0:fc0ddaee005d 337 time_counter.reset();
4180_1 0:fc0ddaee005d 338 time_counter.start();
4180_1 0:fc0ddaee005d 339 while (time_counter.read()<Sequence_Delay[j]) {
4180_1 0:fc0ddaee005d 340 for (i = 0; i < num_LEDS; i++) {
4180_1 0:fc0ddaee005d 341 if (((i+odd)&0x01)==0)
4180_1 0:fc0ddaee005d 342 //Writes 32-bits of RGB color data to LED using SPI hardware
4180_1 0:fc0ddaee005d 343 Write_LED( LED_Color[j][i][0], LED_Color[j][i][1], LED_Color[j][i][2]);
4180_1 0:fc0ddaee005d 344 // Uncomment to get status info on serial port
4180_1 0:fc0ddaee005d 345 // printf("i= %d, j= %d\n\r",i,j);
4180_1 0:fc0ddaee005d 346 // printf(" %d %d %d\n\r",LED_Color[j][i][0], LED_Color[j][i][1], LED_Color[j][i][2]);
4180_1 0:fc0ddaee005d 347 else
4180_1 0:fc0ddaee005d 348 Write_LED( LED_Color[j][i][0]/4, LED_Color[j][i][1]/4, LED_Color[j][i][2]/4);
4180_1 0:fc0ddaee005d 349 }
4180_1 0:fc0ddaee005d 350 //Load in new values just shifted out to LED chain by setting latch high
4180_1 0:fc0ddaee005d 351 wait(.000015);
4180_1 0:fc0ddaee005d 352 latch=1;
4180_1 0:fc0ddaee005d 353 wait(.000015);
4180_1 0:fc0ddaee005d 354 latch=0;
4180_1 0:fc0ddaee005d 355 wait(.15);
4180_1 0:fc0ddaee005d 356 odd = !odd;
4180_1 0:fc0ddaee005d 357 }
4180_1 0:fc0ddaee005d 358 time_counter.stop();
4180_1 0:fc0ddaee005d 359 break;
4180_1 0:fc0ddaee005d 360 }
4180_1 0:fc0ddaee005d 361 case 4: {
4180_1 0:fc0ddaee005d 362 //Lighting Effect: Circular Shift of Colors
4180_1 0:fc0ddaee005d 363 time_counter.reset();
4180_1 0:fc0ddaee005d 364 time_counter.start();
4180_1 0:fc0ddaee005d 365 k=0;
4180_1 0:fc0ddaee005d 366 while (time_counter.read()<Sequence_Delay[j]) {
4180_1 0:fc0ddaee005d 367 k = (k+1)%num_LEDS;
4180_1 0:fc0ddaee005d 368 for (i = 0; i < num_LEDS; i++) {
4180_1 0:fc0ddaee005d 369
4180_1 0:fc0ddaee005d 370 //Writes 32-bits of RGB color data to LED using SPI hardware
4180_1 0:fc0ddaee005d 371 Write_LED( LED_Color[j][(i+k)%num_LEDS][0], LED_Color[j][(i+k)%num_LEDS][1], LED_Color[j][(i+k)%num_LEDS][2]);
4180_1 0:fc0ddaee005d 372 // Uncomment to get status info on serial port
4180_1 0:fc0ddaee005d 373 // printf("i= %d, j= %d\n\r",i,j);
4180_1 0:fc0ddaee005d 374 // printf(" %d %d %d\n\r",LED_Color[j][i][0], LED_Color[j][i][1], LED_Color[j][i][2]);
4180_1 0:fc0ddaee005d 375 }
4180_1 0:fc0ddaee005d 376 //Load in new values just shifted out to LED chain by setting latch high
4180_1 0:fc0ddaee005d 377 wait(.000015);
4180_1 0:fc0ddaee005d 378 latch=1;
4180_1 0:fc0ddaee005d 379 wait(.000015);
4180_1 0:fc0ddaee005d 380 latch=0;
4180_1 0:fc0ddaee005d 381 wait(.10);
4180_1 0:fc0ddaee005d 382 }
4180_1 0:fc0ddaee005d 383 time_counter.stop();
4180_1 0:fc0ddaee005d 384 break;
4180_1 0:fc0ddaee005d 385 case 5: {
4180_1 0:fc0ddaee005d 386 //Random Bright Colors
4180_1 0:fc0ddaee005d 387 time_counter.reset();
4180_1 0:fc0ddaee005d 388 time_counter.start();
4180_1 0:fc0ddaee005d 389 k=0;
4180_1 0:fc0ddaee005d 390 while (time_counter.read()<Sequence_Delay[j]) {
4180_1 0:fc0ddaee005d 391 k = (k+1)%num_LEDS;
4180_1 0:fc0ddaee005d 392 for (i = 0; i < num_LEDS; i++) {
4180_1 0:fc0ddaee005d 393
4180_1 0:fc0ddaee005d 394 //Writes 32-bits of RGB color data to LED using SPI hardware
4180_1 0:fc0ddaee005d 395 Write_LED( (rand()&0x00F000)>>6,(rand()&0x00F000)>>6,(rand()&0x00F000)>>6);
4180_1 0:fc0ddaee005d 396 // Uncomment to get status info on serial port
4180_1 0:fc0ddaee005d 397 // printf("i= %d, j= %d\n\r",i,j);
4180_1 0:fc0ddaee005d 398 // printf(" %d %d %d\n\r",LED_Color[j][i][0], LED_Color[j][i][1], LED_Color[j][i][2]);
4180_1 0:fc0ddaee005d 399 }
4180_1 0:fc0ddaee005d 400 //Load in new values just shifted out to LED chain by setting latch high
4180_1 0:fc0ddaee005d 401 wait(.000015);
4180_1 0:fc0ddaee005d 402 latch=1;
4180_1 0:fc0ddaee005d 403 wait(.000015);
4180_1 0:fc0ddaee005d 404 latch=0;
4180_1 0:fc0ddaee005d 405 wait(.08);
4180_1 0:fc0ddaee005d 406 }
4180_1 0:fc0ddaee005d 407 time_counter.stop();
4180_1 0:fc0ddaee005d 408 break;
4180_1 0:fc0ddaee005d 409 }
4180_1 0:fc0ddaee005d 410 }
4180_1 0:fc0ddaee005d 411 }
4180_1 0:fc0ddaee005d 412 }
4180_1 0:fc0ddaee005d 413 }
4180_1 0:fc0ddaee005d 414 }