/* * Abstraction of the LED pixels (HAL) that make up the wreath * this code can be changed to allow the use of different types of * LED pixels and different protocols for different Hardware */ #include #include #define GROUPSZ 1 // pixels per position ie supports multiple // pixels per position // For Pixel String #define CTL_PIN 5 // LED Control Signal Pin rgb_color colors[NUMPIXELS * GROUPSZ]; PololuLedStrip pixels; /* Function Prototypes */ boolean pressed(void); void showHoliday(int i); byte getHoliday(); void setHoliday(byte); const long delay10sec = 10000000; // 10 seconds in micros const long delay1sec = 1000000; // 1 second in micros Bounce debouncer = Bounce(); const long STDDLY = 50; // Lookup holiday number via Name #define NEWYEARS 0 #define MADIGRAS 1 #define EASTER 2 #define SPRING 3 #define SUMMER 4 #define JULY4 5 #define MEMDAY 6 #define FALL 7 #define HALLOWEEN 8 #define XMAS 9 #define maxholiday 10 // change if expanding holidays to 11 or 12 int holiday; // Table holds the RGB values for each of // the colors associated with the current holiday int hcolor[HCWIDTH][CTWIDTH]; int hindx[HCWIDTH]; // just the indices no rgb // Color offsets to use hcolor table #define CR 0 // red #define CG 1 // green #define CB 2 // blue /******************************************************************* * Selection Push Button Interface * Change this code to support different selection hardware * or settings ******************************************************************/ #define BUTTON_PIN 8 // initialization of holiday selection push button void setupPB(){ // Setup the button with an internal pull-up : pinMode(BUTTON_PIN,INPUT_PULLUP); // After setting up the button, setup the Bounce instance : debouncer.attach(BUTTON_PIN); debouncer.interval(100); // interval in ms - adjust as needed for hw } // test for button pressed - return status boolean pressed() { // Update the Bounce instance : debouncer.update(); // Get the updated value : int value = debouncer.read(); // return (value == LOW); if ( value == LOW ) { return true; } else { return false; } } // pressed() /******************************************************************* * LED Pixel Interface * Change this code to support different hardware * All these functions must be implemented for new hardware ******************************************************************/ void setColor( int pos, int red, int green, int blue){ //pixels.setColour(pos, red, green, blue); rgb_color color; // colors do not match due to pixel strings // color order is green, red , blue color.red = green; color.green = red; color.blue = blue; pos *= GROUPSZ; for( int j = 0; j < GROUPSZ; j++) { // fill all of group colors[pos + j] = color; } } void setArrayColor( byte *pix, byte aLen, int red, int green, int blue) { //Serial.println(aLen); rgb_color color; // colors do not match due to pixel strings // color order is green, red , blue color.red = green; color.green = red; color.blue = blue; for (int i = 0; i < aLen; i++) { // fill the output buffer with color //pixels.setColour(pix[i], red, green, blue); int p = pix[i] * GROUPSZ; for( int j = 0; j < GROUPSZ; j++) { // fill all of group colors[p + j] = color; } } } void setArrayIndex(byte *pix, byte aLen, int idx) { for (int i = 0; i < aLen; i++) { setColor(pix[i], hcolor[idx][CR], hcolor[idx][CG], hcolor[idx][CB]); } } // set a single pixel (pix) to the // rgb values in the holiday color table pointed to by idx void setPixelIndex(byte pix, int idx) { setColor(pix, hcolor[idx][CR], hcolor[idx][CG], hcolor[idx][CB]); } // pix is pointer to an table of color numbers // for the current holiday 0-3 // aLen is the size of that table void setAllIndex(byte *pix, byte aLen) { for (int i = 0; i < aLen; i++) { int c = pix[i]; if(c == 99) { // special black code setColor(i, 0, 0, 0); } else { setColor(i, hcolor[c][CR], hcolor[c][CG], hcolor[c][CB]); } } } void pdisplay(void) { pixels.write(colors, NUMPIXELS * GROUPSZ); }