/* * Display effects and helper functions */ /*************************************************************** * Startup FUNCTIONS ***************************************************************/ void fillArray4( byte*); // forward definition prototype // Looks up holiday colors and rgb percent in ROM // then displays the colors for a holiday void showHoliday(int holidayIdx) { // first test -> if at end of holiday table restart byte test = EEPROM.read((holidayIdx * HCWIDTH) + HCSTART); if (test == ENDMK) { holiday = 0; // WARNING modify global as side effect of routine!!! holidayIdx = 0; } // get the 4 colors for the holiday // into hidx (global) byte hidx[CTWIDTH]; for(int hci = 0; hci < HCWIDTH; hci++){ hidx[hci] = EEPROM.read((holidayIdx * HCWIDTH) + hci + HCSTART); } // load global color table for each holiday (hcolor) with actual // rgb values base on percent of max found in the color table int pct; for(int i = 0; i < HCWIDTH; i++) { for (int j = 0; j < CTWIDTH; j++) { pct = EEPROM.read((hidx[i] * CTWIDTH) + j + CTSTART); hcolor[i][j] = (pct * MAXBRITE / 100); } } // display the colors for the holiday byte field[NUMPIXELS]; fillArray4(field); setAllIndex(field, NUMPIXELS); pdisplay(); } // showHoliday() /*************************************************************** * HELPER FUNCTIONS ***************************************************************/ enum COLORS /* allows access colors by name */ { BLACK, RED, GREEN, BLUE, LTPURPLE, DKPURPLE, YELLOW, ORANGE, LTGREEN, CYAN, PINK, MAROON, PEACH, TERQUOISE, DKBLUE, SAPGREEN, DIMWHITE, DKORANGE, LEMON, DKGREEN, WARMWHITE, COOLWHITE, MEDPURPLE, REDORANGE, LILAC, BLUEGREEN, DIMYELLOW, GOLD, PURPLERED, BLUEPURPLE, GREENBLUE, WHITE } cidx; // prototypes for functions in lightControl.h void pdisplay(void); void setColor(int, int, int, int); void setPixelIndex(byte, int); void setAllIndex(byte, byte); void setArrayColor( byte*, byte, int, int, int); // array control functions void shiftArrayUp(byte *array, int aSize) { // store upper count members in temp byte temp = array[aSize - 1]; for (int i = aSize - 1; i > 0 ; i--) { array[i] = array[i-1]; } array[0] = temp; } void shiftArrayDn(byte *array, int aSize) { // store upper count members in temp byte temp = array[0]; for (int i = 1; i < aSize ; i++) { array[i - 1] = array[i]; } array[aSize - 1] = temp; } // Set the entire output to Black (turn off) void allBlack(){ for (int i = 0; i < NUMPIXELS; i++) { setColor(i, 0, 0, 0); } pdisplay(); // This sends the updated pixel colors to the hardware. } // allBlack() // Set the entire output to one of the colors (pixcolor = 0 to 3)for the // selected holiday void allColor(int pixcolor){ byte r, g, b; r = hcolor[pixcolor][CR]; g = hcolor[pixcolor][CG]; b = hcolor[pixcolor][CB]; for (int i = 0; i < NUMPIXELS; i++) { setColor(i, r, g, b); } } // allColor() // Set all even output positions to a color // and delay void showColorEven(int coloridx, long rate) { for ( int i = 0; i < NUMPIXELS; i++) { if ( i % 2 == 0) { setPixelIndex(i, coloridx); pdisplay(); delay(rate); } } } // showColorEven() // Set all odd output positions to a color // and delay void showColorOdd(int coloridx, long rate) { for ( int i = 0; i < NUMPIXELS; i++) { if ( i % 2 != 0) { setPixelIndex(i, coloridx); pdisplay(); delay(rate); } } } // showColorOdd() // set output array to the holiday colors // each color filling 4 output positions void fillArray4( byte *field) { // load one color each quardrent for( int i = 0; i < NUMPIXELS; i++) { switch( i / 4 ) { case 0: field[i] = 0; break; case 1: field[i] = 1; break; case 2: field[i] = 2; break; default: field[i] = 3; break; } // switch } // for } // fillArray4() // set output array to the holiday colors // each color filling 2 output positions void fillArray2(byte *field) { for( int i = 0; i < NUMPIXELS; i++) { switch( i / 2 ) { case 0: field[i] = 0; break; case 1: field[i] = 1; break; case 2: field[i] = 2; break; case 3: field[i] = 3; break; case 4: field[i] = 0; break; case 5: field[i] = 1; break; case 6: field[i] = 2; break; default: field[i] = 3; break; } // switch } // for } // fillArray2() void fillChase4(byte *field){ // load fields array with colors and black for (int f = 0; f < NUMPIXELS; f++) { switch(f){ case 0: field[f] = 0; break; case 4: field[f] = 1; break; case 8: field[f] = 2; break; case 12: field[f] = 3; break; default: field[f] = 99; break; } // switch } // for } // loadchase4() void rotUp(byte *field, int repeat, long rate){ for (int i = 0 ; i < (NUMPIXELS * repeat); i++) { setAllIndex(field, NUMPIXELS); delay(rate); pdisplay(); shiftArrayUp(field, NUMPIXELS); } } // rotUp() void rotDn(byte *field, int repeat, long rate){ for (int i = 0 ; i < (NUMPIXELS * repeat); i++) { setAllIndex(field, NUMPIXELS); delay(rate); pdisplay(); shiftArrayDn(field, NUMPIXELS); } } // rotDn() /***************************************************************** * LIBRARY OF DISPLAY FUNCTIONS ******************************************************************/ // Build wreath add position at a time till full // then turn them off at once // NOTE: Parameters required for All display functions: // repeat Number of times the pattern is repeated // rate The amount of delay in milliseconds between changes void all4On(int repeat, long rate) { for (int j = repeat; j >= 0; j--) { allBlack(); for (int i = 0; i < NUMPIXELS; i++) { // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 switch(i % 4) { case 0: setPixelIndex(i, 0); break; case 1: setPixelIndex(i, 1); break; case 2: setPixelIndex(i, 2); break; default: setPixelIndex(i, 3); break; } // switch pdisplay(); // This sends the updated pixel color to the hardware. delay(rate); // Delay for a period of time (in milliseconds). } // for all pixels allBlack(); } // repeat } // all4On() // build wreath add one pixel at a time till full // then turn them off at once void all3On(int repeat, long rate) { for (int j = repeat; j >= 0; j--) { allBlack(); for (int i = 0; i < NUMPIXELS; i++) { // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 switch(i % 3) { case 0: setPixelIndex(i, 0); break; case 1: setPixelIndex(i, 1); break; default: setPixelIndex(i, 2); break; } // switch pdisplay(); // send the output position colors to the hardware. delay(rate); // Delay for a period of time (in milliseconds). } // for all pixels allBlack(); } // repeat } // all3On() // build wreath add one pixel at a time till full // then turn them off at once void all2On(int repeat, long rate) { for (int j = repeat; j >= 0; j--) { allBlack(); for (int i = 0; i < NUMPIXELS; i++) { switch(i % 2) { case 0: setPixelIndex(i, 0); break; default: setPixelIndex(i, 1); break; } // switch pdisplay(); // This sends the updated pixel color to the hardware. delay(rate); // Delay for a period of time (in milliseconds). } // for all pixels allBlack(); } // repeat } // all2On() // Display base color 0 then change odd // positions to color1 one at a time void add1ToBase0(int repeat, long rate) { //base wreath adding secondary color for (int j = 0; j < repeat; j++) { allColor(0); pdisplay(); delay(rate); showColorEven(1, rate); } // repeat } // add1ToBase0() // Display base color0 then change odd // positions to color2 one at a time void add2ToBase0(int repeat, long rate) { //base wreath adding secondary color for (int j = 0; j < repeat; j++) { allColor(0); pdisplay(); delay(rate); showColorEven(2, rate); } // repeat } // add2ToBase0() // Display base color0 then change odd // positions to color3 one at a time void add3ToBase0(int repeat, long rate) { //base wreath adding secondary color for (int j = 0; j < repeat; j++) { allColor(0); pdisplay(); delay(rate); showColorEven(3, rate); } // repeat } // add3ToBase0() // Display base color1 then change odd // positions to color2 one at a time void add2ToBase1(int repeat, long rate) { //base wreath adding secondary color for (int j = 0; j < repeat; j++) { allColor(1); pdisplay(); delay(rate); showColorEven(2, rate); } // repeat } // add2ToBase1() // Display base color1 then change odd // positions to color3 one at a time void add3ToBase1(int repeat, long rate) { //base wreath adding secondary color for (int j = 0; j < repeat; j++) { allColor(1); pdisplay(); delay(rate); showColorEven(3, rate); } // repeat } // add3ToBase1() // Display base color2 then change odd // positions to color3 one at a time void add3ToBase2(int repeat, long rate) { //base wreath adding secondary color for (int j = 0; j < repeat; j++) { allColor(2); pdisplay(); delay(rate); showColorEven(3, rate); } // repeat } // add3ToBase2() // build wreath add one position at a time using all 4 // colors till full then turn them off one at a time void all4OnOff(int repeat, long rate) { for (int j = repeat; j >= 0; j--) { allBlack(); for (int i = 0; i < NUMPIXELS; i++) { // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 switch(i % 4) { case 0: setPixelIndex(i, 0); break; case 1: setPixelIndex(i, 1); break; case 2: setPixelIndex(i, 2); break; default: setPixelIndex(i, 3); break; } // switch pdisplay(); // send colors to the hardware. delay(rate); // Delay for a period of time (in milliseconds). } // for all pixels for (int i = 0; i < NUMPIXELS; i++) { setPixelIndex(i, BLACK); pdisplay(); // send colors to the hardware. delay(rate); // Delay for a period of time (in milliseconds). } allBlack(); } } // all4OnOff() // build wreath add one position at a time till full // using colors 0-2 // then turn them off one at a time till all off void all3OnOff(int repeat, long rate) { for (int j = repeat; j >= 0; j--) { allBlack(); for (int i = 0; i < NUMPIXELS; i++) { // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 switch(i % 3) { case 0: setPixelIndex(i, 0); break; case 1: setPixelIndex(i, 1); break; default: setPixelIndex(i, 2); break; } // switch pdisplay(); // This sends the updated pixel color to the hardware. delay(rate); // Delay for a period of time (in milliseconds). } // for all pixels for (int i = 0; i < NUMPIXELS; i++) { setPixelIndex(i, BLACK); pdisplay(); // This sends the updated pixel color to the hardware. delay(rate); // Delay for a period of time (in milliseconds). } allBlack(); } } // all3OnOff() // build wreath add one position at a time till full // using colors 0 & 1 // then turn them off one at a time till all off void all2OnOff(int repeat, long rate) { for (int j = repeat; j >= 0; j--) { allBlack(); for (int i = 0; i < NUMPIXELS; i++) { switch(i % 2) { case 0: setPixelIndex(i, 0); break; default: setPixelIndex(i, 1); break; } // switch pdisplay(); // This sends the updated pixel color to the hardware. delay(rate); // Delay for a period of time (in milliseconds). } // for all pixels for (int i = 0; i < NUMPIXELS; i++) { setPixelIndex(i, BLACK); pdisplay(); // This sends the updated pixel color to the hardware. delay(rate); // Delay for a period of time (in milliseconds). } allBlack(); } } // all2OnOff() // alternate display all pixels // between two colors color indicies to use // ex alternate01 uses indices 0 and 1 void alternate01(int repeat, long rate) { byte field[NUMPIXELS]; // Fill fields array with color numbers. for(int j = 0; j < NUMPIXELS; j++){ field[j] = j % 2; } for (int i = repeat; i >= 0; i--) { // alternate flashes repeat times setAllIndex(field, NUMPIXELS); pdisplay(); delay(rate); shiftArrayDn(field, NUMPIXELS); } // for repeat } // alternate01() // alternate display all pixels // between two colors color indicies to use // ex alternate01 uses indices 0 and 1 void alternate02(int repeat, long rate) { byte field[NUMPIXELS]; // Fill fields array with color numbers. for(int j = 0; j < NUMPIXELS; j++){ if((j % 2) == 0) { field[j] = 0; } else { field[j] = 2; } } for (int i = repeat; i >= 0; i--) { // alternate flashes repeat times setAllIndex(field, NUMPIXELS); pdisplay(); delay(rate); shiftArrayDn(field, NUMPIXELS); } // for repeat } // alternate02() // alternate display all pixels // between two colors color indicies to use // ex alternate01 uses indices 0 and 1 void alternate03(int repeat, long rate) { byte field[NUMPIXELS]; // Fill fields array with color numbers. for(int j = 0; j < NUMPIXELS; j++){ if((j % 2) == 0) { field[j] = 0; } else { field[j] = 3; } } for (int i = repeat; i >= 0; i--) { // alternate flashes repeat times setAllIndex(field, NUMPIXELS); pdisplay(); delay(rate); shiftArrayDn(field, NUMPIXELS); } // for repeat } // alternate03() // alternate display all pixels // between two colors color indicies to use // ex alternate01 uses indices 0 and 1 void alternate12(int repeat, long rate) { byte field[NUMPIXELS]; // Fill fields array with color numbers. for(int j = 0; j < NUMPIXELS; j++){ field[j] = (j % 2) + 1; } for (int i = repeat; i >= 0; i--) { // alternate flashes repeat times setAllIndex(field, NUMPIXELS); pdisplay(); delay(rate); shiftArrayDn(field, NUMPIXELS); } // for repeat } // alternate12() // alternate display all pixels // between two colors color indicies to use // ex alternate01 uses indices 0 and 1 void alternate13(int repeat, long rate) { byte field[NUMPIXELS]; // Fill fields array with color numbers. for(int j = 0; j < NUMPIXELS; j++){ if((j % 2) == 0) { field[j] = 1; } else { field[j] = 3; } } for (int i = repeat; i >= 0; i--) { // alternate flashes repeat times setAllIndex(field, NUMPIXELS); pdisplay(); delay(rate); shiftArrayDn(field, NUMPIXELS); } // for repeat } // alternate13() // alternate display all pixels // between two colors color indicies to use // ex alternate01 uses indices 0 and 1 void alternate23(int repeat, long rate) { byte field[NUMPIXELS]; // Fill fields array with color numbers. for(int j = 0; j < NUMPIXELS; j++){ field[j] = (j % 2) + 2; } for (int i = repeat; i >= 0; i--) { // alternate flashes repeat times setAllIndex(field, NUMPIXELS); pdisplay(); delay(rate); shiftArrayDn(field, NUMPIXELS); } // for repeat } // alternate23() void shiftUp3(int repeat, long rate ){ byte field[NUMPIXELS]; // build field array with 3 colors for(int i = 0; i < NUMPIXELS; i++) { switch( i % 3) { case 0: field[i] = 0; break; case 1: field[i] = 1; break; default: field[i] = 2; } } for (int i = repeat; i >= 0; i -= 2) { // alternate flashes repeat times setAllIndex(field, NUMPIXELS); pdisplay(); delay(rate); shiftArrayUp(field, NUMPIXELS); } // for repeat } /// shiftUp3() void shiftDn3(int repeat, long rate ){ byte field[NUMPIXELS]; // build field array with 3 colors for(int i = 0; i < NUMPIXELS; i++) { switch( i % 3) { case 0: field[i] = 0; break; case 1: field[i] = 1; break; default: field[i] = 2; } } for (int i = repeat; i >= 0; i -= 2) { // alternate flashes repeat times setAllIndex(field, NUMPIXELS); pdisplay(); delay(rate); shiftArrayDn(field, NUMPIXELS); } // for repeat } /// shiftDn3() void rotateUp4(int repeat, long rate) { byte field[NUMPIXELS]; fillArray4(field); rotUp(field, repeat, rate); } // rotateUp4 void rotateUp2(int repeat, long rate) { byte field[NUMPIXELS]; fillArray2(field); rotUp(field, repeat, rate); } void rotateUp1(int repeat, long rate) { byte field[NUMPIXELS]; for( int i = 0; i < NUMPIXELS; i++) { field[i] = i % 4; } rotUp(field, repeat, rate); } void rotateDn4(int repeat, long rate) { byte field[NUMPIXELS]; fillArray4(field); rotDn(field, repeat, rate); } void rotateDn2(int repeat, long rate) { byte field[NUMPIXELS]; fillArray2(field); rotDn(field, repeat, rate); } void rotateDn1(int repeat, long rate) { byte field[NUMPIXELS]; // fill target array for( int i = 0; i < NUMPIXELS; i++) { field[i] = i % 4; } rotDn(field, repeat, rate); } void whiteFlashing(int repeat, long rate) { // white random flashes for ( int i = 0; i < repeat; i++) { allBlack(); byte r = random(NUMPIXELS); //turn on one pixel white setColor(r, MAXBRITE, MAXBRITE, MAXBRITE); pdisplay(); delay(rate/100); } allBlack(); } void multiFlashing(int repeat, long rate){ // Multi Color repeat for ( int i = 0; i < repeat; i++) { allBlack(); byte r = random(NUMPIXELS); int color = random(0, HCWIDTH); // use holiday colors pdisplay(); setPixelIndex(r, color); pdisplay(); delay(rate/100); } // repeat allBlack(); } // multiFlashing() // fade colors 0 & 1 in and out void fadeTwo01(int repeat, long rate ) { int oddRedVal = hcolor[1][0]; int oddGreenVal = hcolor[1][1]; int oddBlueVal = hcolor[1][2]; int evenRedVal = hcolor[0][0]; int evenGreenVal = hcolor[0][1]; int evenBlueVal = hcolor[0][2]; // set up pixel groups byte even[NUMPIXELS / 2]; byte odd[NUMPIXELS / 2]; byte part = 0; for ( byte i = 0; i < NUMPIXELS; i++) { if ((i % 2) == 0) { even[part] = i; } else { odd[part] = i; part++; } } // for for (int j = 0; j <= repeat; j++) { // three times for (int i = BMAX; i >= 0; i -= (BMAX/30)) { // fade down in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } //fade down for (int i = 0; i <= BMAX; i += (BMAX/30)) { // fade up in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } // fade up } // repeat times // turn them off allBlack(); } // fadeTwo01() // fade colors 0 & 2 in and out void fadeTwo02(int repeat, long rate ) { int oddRedVal = hcolor[2][0]; int oddGreenVal = hcolor[2][1]; int oddBlueVal = hcolor[2][2]; int evenRedVal = hcolor[0][0]; int evenGreenVal = hcolor[0][1]; int evenBlueVal = hcolor[0][2]; // set up pixel groups byte even[NUMPIXELS / 2]; byte odd[NUMPIXELS / 2]; byte part = 0; for ( byte i = 0; i < NUMPIXELS; i++) { if ((i % 2) == 0) { even[part] = i; } else { odd[part] = i; part++; } } // for for (int j = 0; j <= repeat; j++) { // three times for (int i = BMAX; i >= 0; i -= (BMAX/30)) { // fade down in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } //fade down for (int i = 0; i <= BMAX; i += (BMAX/30)) { // fade up in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } // fade up } // repeat times // turn them off allBlack(); } // fadeTwo02() // fade colors 0 & 3 in and out // NOTE *colors not needed void fadeTwo03(int repeat, long rate ) { int oddRedVal = hcolor[3][0]; int oddGreenVal = hcolor[3][1]; int oddBlueVal = hcolor[3][2]; int evenRedVal = hcolor[0][0]; int evenGreenVal = hcolor[0][1]; int evenBlueVal = hcolor[0][2]; // set up pixel groups byte even[NUMPIXELS / 2]; byte odd[NUMPIXELS / 2]; byte part = 0; for ( byte i = 0; i < NUMPIXELS; i++) { if ((i % 2) == 0) { even[part] = i; } else { odd[part] = i; part++; } } // for for (int j = 0; j <= repeat; j++) { // three times for (int i = BMAX; i >= 0; i -= (BMAX/30)) { // fade down in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } //fade down for (int i = 0; i <= BMAX; i += (BMAX/30)) { // fade up in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } // fade up } // repeat times // turn them off allBlack(); } // fadeTwo03() // fade colors 1 & 2 in and out void fadeTwo12(int repeat, long rate ) { int oddRedVal = hcolor[2][0]; int oddGreenVal = hcolor[2][1]; int oddBlueVal = hcolor[2][2]; int evenRedVal = hcolor[1][0]; int evenGreenVal = hcolor[1][1]; int evenBlueVal = hcolor[1][2]; // set up pixel groups byte even[NUMPIXELS / 2]; byte odd[NUMPIXELS / 2]; byte part = 0; for ( byte i = 0; i < NUMPIXELS; i++) { if ((i % 2) == 0) { even[part] = i; } else { odd[part] = i; part++; } } // for for (int j = 0; j <= repeat; j++) { // three times for (int i = BMAX; i >= 0; i -= (BMAX/30)) { // fade down in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } //fade down for (int i = 0; i <= BMAX; i += (BMAX/30)) { // fade up in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } // fade up } // repeat times // turn them off allBlack(); } // fadeTwo12() // fade colors 1 & 3 in and out void fadeTwo13(int repeat, long rate ) { int oddRedVal = hcolor[3][0]; int oddGreenVal = hcolor[3][1]; int oddBlueVal = hcolor[3][2]; int evenRedVal = hcolor[1][0]; int evenGreenVal = hcolor[1][1]; int evenBlueVal = hcolor[1][2]; byte even[NUMPIXELS / 2]; byte odd[NUMPIXELS / 2]; byte part = 0; for ( byte i = 0; i < NUMPIXELS; i++) { if ((i % 2) == 0) { even[part] = i; } else { odd[part] = i; part++; } } // for for (int j = 0; j <= repeat; j++) { // three times for (int i = BMAX; i >= 0; i -= (BMAX/30)) { // fade down in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } //fade down for (int i = 0; i <= BMAX; i += (BMAX/30)) { // fade up in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } // fade up } // repeat times // turn them off allBlack(); } // fadeTwo13() // fade colors 2 & 3 in and out void fadeTwo23(int repeat, long rate ) { int oddRedVal = hcolor[3][0]; int oddGreenVal = hcolor[3][1]; int oddBlueVal = hcolor[3][2]; int evenRedVal = hcolor[2][0]; int evenGreenVal = hcolor[2][1]; int evenBlueVal = hcolor[2][2]; // set up pixel groups byte even[NUMPIXELS / 2]; byte odd[NUMPIXELS / 2]; byte part = 0; for ( byte i = 0; i < NUMPIXELS; i++) { if ((i % 2) == 0) { even[part] = i; } else { odd[part] = i; part++; } } // for for (int j = 0; j <= repeat; j++) { // three times for (int i = BMAX; i >= 0; i -= (BMAX/30)) { // fade down in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } //fade down for (int i = 0; i <= BMAX; i += (BMAX/30)) { // fade up in 30 steps float x = (((float) i ))/ BMAX; setArrayColor(even, sizeof(even), (int) evenRedVal * x, (int) evenGreenVal * x, (int) evenBlueVal * x); setArrayColor(odd, sizeof(odd), (int) oddRedVal * x, (int) oddGreenVal * x, (int) oddBlueVal * x); pdisplay(); delay(rate / 10); } // fade up } // repeat times // turn them off allBlack(); } // fadeTwo23() void fireWorks0(int repeat, long rate ) { int RedVal = hcolor[0][0]; int GreenVal = hcolor[0][1]; int BlueVal = hcolor[0][2]; for (int j = 0; j < repeat; j++) { // do repeat times // show full brightness allColor(0); pdisplay(); delay(1000); for (int i = BMAX; i >= 0; i -= (BMAX/50)) { // fade down in steps float x = ((float) i )/ BMAX; for(int i = 0; i < NUMPIXELS; i++) { setColor(i, (int) RedVal * x, (int) GreenVal * x, (int) BlueVal * x); } pdisplay(); delay(rate / 10); } // fade dn delay(500 * random(5)); } // repeat times // turn them off allBlack(); } void fireWorks1(int repeat, long rate ) { int RedVal = hcolor[1][0]; int GreenVal = hcolor[1][1]; int BlueVal = hcolor[1][2]; for (int j = 0; j < repeat; j++) { // do repeat times // show full brightness allColor(1); pdisplay(); delay(1000); for (int i = BMAX; i >= 0; i -= (BMAX/50)) { // fade down in steps float x = ((float) i )/ BMAX; for(int i = 0; i < NUMPIXELS; i++) { setColor(i, (int) RedVal * x, (int) GreenVal * x, (int) BlueVal * x); } pdisplay(); delay(rate / 10); } // fade dn delay(500 * random(5)); } // repeat times // turn them off allBlack(); } void fireWorks2(int repeat, long rate ) { int RedVal = hcolor[2][0]; int GreenVal = hcolor[2][1]; int BlueVal = hcolor[2][2]; for (int j = 0; j < repeat; j++) { // do repeat times // show full brightness allColor(2); pdisplay(); delay(1000); for (int i = BMAX; i >= 0; i -= (BMAX/50)) { // fade down in steps float x = ((float) i )/ BMAX; for(int i = 0; i < NUMPIXELS; i++) { setColor(i, (int) RedVal * x, (int) GreenVal * x, (int) BlueVal * x); } pdisplay(); delay(rate / 10); } // fade dn delay(500 * random(5)); } // repeat times // turn them off allBlack(); } void fireWorks3(int repeat, long rate ) { int RedVal = hcolor[3][0]; int GreenVal = hcolor[3][1]; int BlueVal = hcolor[3][2]; for (int j = 0; j < repeat; j++) { // do repeat times // show full brightness allColor(3); pdisplay(); delay(1000); for (int i = BMAX; i >= 0; i -= (BMAX/50)) { // fade down in steps float x = ((float) i )/ BMAX; for(int i = 0; i < NUMPIXELS; i++) { setColor(i, (int) RedVal * x, (int) GreenVal * x, (int) BlueVal * x); } pdisplay(); delay(rate / 10); } // fade dn delay(500 * random(5)); } // repeat times // turn them off allBlack(); } void chaseUpAllx4(int repeat, long rate ) { byte field[NUMPIXELS]; allBlack(); fillChase4(field); rotUp(field, repeat, rate); allBlack(); } // chaseUpAllx4() void chaseDnAllx4(int repeat, long rate ) { byte field[NUMPIXELS]; allBlack(); fillChase4(field); rotDn(field, repeat, rate); allBlack(); } // chaseDnAllx4() /*************************************************************** * DISPLAY FUNCTION ACCESS ***************************************************************/ // function pointer definition prototype typedef void (*dispfunct) (int repeat, long rate ); // function pointer array - add new function names to list const dispfunct functlist[] = { all4On, all3On, all2On, add1ToBase0, add2ToBase0, add3ToBase0, add2ToBase1, add3ToBase1, add3ToBase2, all4OnOff, all3OnOff, all2OnOff, alternate01, alternate02, alternate03, alternate12, alternate13, alternate23, shiftUp3, shiftDn3, rotateUp4, rotateUp2, rotateUp1, rotateDn4, rotateDn2, rotateDn1, whiteFlashing, multiFlashing, fadeTwo01, fadeTwo02, fadeTwo03, fadeTwo12, fadeTwo13, fadeTwo23, fireWorks0, fireWorks1, fireWorks2, fireWorks3, chaseUpAllx4, chaseDnAllx4 }; // Pass the display function name, repeat and rate to this function // to display it. void callfunct( dispfunct function, int repeat, long rate) { function(repeat, rate); } // Table of Holidays and Display values // elements for EEROM based holiday display table // used to access the table elments struct Display { byte holidaynum; byte functnum; byte repeat; byte delayfactor; //1 = 50 ms, 20 = 1 sec }; // elements for the patterns displayed for a holiday struct RamDTable { // elements for dtable byte functnum; byte repeat; byte delayfactor; //1 = 50 ms, 20 = 1 sec }; #define MAXDTABLE 40 // All the patterns for the selected holiday are copied into this table // and cntdtable assigned at startup // only the patterns for a single holiday are placed into this table RamDTable dtable[MAXDTABLE]; // each holiday can have up to 40 different patterns int cntdtable; // actual count of entries in dtable /* Table showing the index number in functlist corresponding to * the display function name ( optional but suggested) also update * the holiday display table load function utility (LoadDtable) * * Function Name Index Description */ #define all4On 0 // C 0-3 add one pixel at a time till full #define all3On 1 // C 0-2 add one pixel at a time till full #define all2On 2 // C 0&1 add one pixel at a time till full #define add1ToBase0 3 // add one C 1 pixel at a time to all C0 #define add2ToBase0 4 // add one C 2 pixel at a time to all C0 #define add3ToBase0 5 // add one C 3 pixel at a time to all C0 #define add2ToBase1 6 // add one C 2 pixel at a time to all C1 #define add3ToBase1 7 // add one C 3 pixel at a time to all C1 #define add3ToBase2 8 // add one C 3 pixel at a time to all C2 #define all4OnOff 9 // Use C 0-3 add one pixel at a time then // turn off one at a time #define all3OnOff 10 // Use C 0-2 " #define all2OnOff 11 // Use C 0 & 1 #define alternate01 12 // Even odd alternating between C 0 & 1 #define alternate02 13 // Even odd alternating between C 0 & 2 #define alternate03 14 // Even odd alternating between C 0 & 2 #define alternate12 15 // Even odd alternating between C 2 & 1 #define alternate13 16 // Even odd alternating between C 3 & 1 #define alternate23 17 // Even odd alternating between C 2 & 3 #define shiftUp3 18 // Using C 0-2 move counter-clockwise #define shiftDn3 19 // Using C 0-2 move clockwise #define rotateUp4 20 // using C 0-3 in groups of 4 move CCW #define rotateUp2 21 // using C 0-3 in groups of 3 move CCW #define rotateUp1 22 // using C 0-3 in groups of 1 move CCW #define rotateDn4 23 // using C 0-2 in quadrents move CW #define rotateDn2 24 // using C 0-3 in groups of 3 move CW #define rotateDn1 25 // using C 0-3 in groups of 1 move CW #define whiteFlashing 26 // random single pixel rapid flashes white #define multiFlashing 27 // random single pixel rapid flashes C 0-4 #define fadeTwo01 28 // Two color fade in then out C 0&1 #define fadeTwo02 29 // Two color fade in then out C 0&2 #define fadeTwo03 30 // Two color fade in then out C 0&3 #define fadeTwo12 31 // Two color fade in then out C 2&1 #define fadeTwo13 32 // Two color fade in then out C 3&1 #define fadeTwo23 33 // Two color fade in then out C 2&3 #define fireWorks0 34 // Using C 0 delay Full brightness slow fade #define fireWorks1 35 // Using C 1 delay Full brightness slow fade #define fireWorks2 36 // Using C 2 delay Full brightness slow fade #define fireWorks3 37 // Using C 3 delay Full brightness slow fade #define chaseUpAllx4 38 // One pixel lit for each of C 0-3 evenly // spaced move CCW #define chaseDnAllx4 39 // One pixel lit for each of C 0-3 evenly // spaced move CW // Sample of holiday display table definition in EEPROM // holiday#, display pattern, repeat#, speed (10 = ~ 1/2 sec) //const struct Display disptable[] = { // {NEWYEARS, all2On, 3, 10}, // {NEWYEARS, add3ToBase2, 3, 10}, // {NEWYEARS, all4On, 3, 6}, // {NEWYEARS, shiftUp3, 6, 10}, // {NEWYEARS, rotateDn2, 3, 10}, // {NEWYEARS, fireWorks1, 5, 10}, // {NEWYEARS, fireWorks2, 5, 10}, // {NEWYEARS, fireWorks3, 4, 10}, // {NEWYEARS, multiFlashing, 200, 20}, // {NEWYEARS, whiteFlashing, 200, 40}, // // {MADIGRAS, all3On, 5, 5}, // {MADIGRAS, alternate01, 3, 20}, // {MADIGRAS, alternate02, 5, 10}, // {MADIGRAS, alternate12, 3, 20}, // {MADIGRAS, alternate03, 5, 10}, // {MADIGRAS, add2ToBase0, 5, 10}, // {MADIGRAS, add1ToBase0, 5, 10}, // {MADIGRAS, add2ToBase1, 5, 10}, // {MADIGRAS, fadeTwo12, 3, 10}, // {MADIGRAS, fadeTwo03, 3, 10}, // {MADIGRAS, rotateUp2, 5, 10}, // {MADIGRAS, rotateDn2, 5, 2}, // {MADIGRAS, all3OnOff, 10, 2}, // // {EASTER, alternate01, 5, 10}, // {EASTER, rotateUp4, 10, 10}, // {EASTER, alternate23, 5, 10}, // {EASTER, alternate12, 5, 5}, // {EASTER, alternate03, 5, 10}, // {EASTER, fadeTwo13, 5, 10}, // {EASTER, chaseUpAllx4, 6, 5}, // {EASTER, chaseDnAllx4, 6, 5}, // // {SPRING, fadeTwo01, 5, 10}, // {SPRING, rotateDn1, 5, 10}, // {SPRING, rotateUp4, 5, 4}, // {SPRING, fadeTwo03, 8, 10}, // {SPRING, fadeTwo13, 5, 10}, // {SPRING, fadeTwo23, 5, 4}, // {SPRING, fadeTwo12, 8, 20}, // {SPRING, fadeTwo13, 5, 10}, // {SPRING, chaseDnAllx4, 5, 4}, // // {SUMMER, rotateUp4, 10, 6}, // {SUMMER, rotateDn4, 10, 6}, // {SUMMER, alternate23, 10, 8}, // {SUMMER, alternate01, 10, 8}, // {SUMMER, shiftUp3, 10, 10}, // {SUMMER, rotateDn2, 10, 6}, // {SUMMER, rotateUp1, 10, 6}, // {SUMMER, all4OnOff, 10, 6}, // // {JULY4, all3On, 3, 10}, // {JULY4, chaseDnAllx4, 15, 2}, // {JULY4, chaseUpAllx4, 5, 15}, // {JULY4, fireWorks0, 3, 10}, // {JULY4, fireWorks2, 2, 10}, // {JULY4, fireWorks1, 3, 10}, // {JULY4, fireWorks0, 2, 10}, // {JULY4, alternate01, 15, 10}, // {JULY4, alternate12, 15, 10}, // {JULY4, fireWorks2, 3, 10}, // {JULY4, fireWorks1, 2, 10}, // {JULY4, multiFlashing, 110, 10}, // {JULY4, whiteFlashing, 200, 10}, // // {MEMDAY, chaseDnAllx4, 3, 10}, // {MEMDAY, chaseUpAllx4, 3, 10}, // {MEMDAY, alternate23, 3, 10}, // {MEMDAY, alternate01, 3, 10}, // {MEMDAY, fadeTwo02, 3, 10}, // {MEMDAY, fadeTwo23, 3, 10}, // {MEMDAY, fadeTwo12, 3, 10}, // {MEMDAY, fadeTwo01, 3, 10}, // {MEMDAY, fadeTwo13, 3, 10}, // {MEMDAY, all4OnOff, 3, 10}, // // {FALL, all2On, 5, 10}, // {FALL, all3On, 5, 10}, // {FALL, add2ToBase1, 10, 10}, // {FALL, add1ToBase0, 10, 10}, // {FALL, add3ToBase1, 10, 10}, // {FALL, rotateUp1, 10, 5}, // {FALL, shiftDn3, 10, 8}, // {FALL, fadeTwo23, 5, 10}, // // {HALLOWEEN, rotateUp4, 3, 9}, // {HALLOWEEN, rotateUp2, 10, 5}, // {HALLOWEEN, all3On, 3, 5}, // {HALLOWEEN, add3ToBase2, 3, 5}, // {HALLOWEEN, add2ToBase1, 3, 5}, // {HALLOWEEN, rotateUp1, 5, 5}, // {HALLOWEEN, rotateUp2, 3, 5}, // {HALLOWEEN, all4On, 8, 10}, // // {XMAS, all2OnOff, 5, 8}, // {XMAS, add1ToBase0, 7, 8}, // {XMAS, alternate01, 7, 15}, // {XMAS, chaseDnAllx4, 5, 8}, // {XMAS, chaseUpAllx4, 7, 8}, // {XMAS, alternate01, 7, 15}, // {XMAS, rotateUp4, 5, 8}, // {XMAS, add3ToBase2, 7, 8}, // {XMAS, rotateDn4, 7, 15}, // // {99, 0, 0, 0} // end of list marker // };